Wish Keyword 'Until' for an 'for' loop.

Discussion in 'Bugs & wishlist' started by zuibaf, May 17, 2018 at 7:39 PM.

Tags:
  1. zuibaf

    zuibaf New Member Licensed User

    Dim fb() As Int
    fb = Array As Int(0, 1, 2, 3, 4)

    Dim uA As Int


    In order to print a zero-based arrangement, we must iterate from 0 to the length of the arrangement minus 1, using the for loop, it could exist in the language, also, a for loop using in place of the keyword 'to' the word 'until' indicates that the for loop will be iterated as long as the loop variable 'for' is less than the limit. That is, there would be two forms of for: for to and for until.

    For uA = 0 To fb.Length - 1
    Log("uA = " + fb(uA))
    Next


    For uA = 0 Until fb.Length
    Log("UA = " + fb(uA))
    Next

    In the 'for to' loop, the sentences within the for loop are iterated while the iteration variable is less than or equal to the limit.
    In this, second, 'for until', the sentences within the for loop are iterated as long as the iteration variable is less than the limit.
    For example, comparing with the C language, it would look something like this:
    for (int uA = 0; uA <5; uA ++)
    So, instead of the user always putting minus -1, in the limit variable, it uses the 'until' sentence that indicates that the sentences within the will be iterated while the iteration variable is smaller than the limit.
     
    Last edited: May 17, 2018 at 8:05 PM
  2. DonManfred

    DonManfred Expert Licensed User

    Code:
    while fb.Length < 123
       
    ' Do whatever you want
    loop
     
    jmon likes this.
  3. zuibaf

    zuibaf New Member Licensed User

    I am not a beginner in programming, I already know other languages, C, C++, C#, in all of them, the loop is very flexible. However, in basic, the loop is not so flexible, for example, if your intent is to indicate that the variable must iterate the for loop while the variable is less than the limit, you must increment an limite it by -1. I believe that the 'until' keyword being added to the loop will make the loop more flexible.
    Although the 'while' loop can be used, however, I think using the while loop is best in situations where the iteration variable will increment in different values at each iteration, for example, depending on the value, it suffers some kind of increment.


    I know two languages based on basic, called Monkey2 and CerberusX, based on Monkey, for creating games, using the same code base, which compiles for linux, mac, windows and other platforms, which uses the keyword 'until' and also 'to' in the for loop, making the loop very flexible.

    https://www.cerberus-x.com/community/cxDocs/Programming_Keywords_For.html
     
Loading...