Ranged For loop
Quick Recap
Last time, we saw the basics of variable declaration. Now let’s move on to loops.
Currently, the for loop doesn't except already declared variables as loop variables. The example given directly below will throw an ArrayIndexOutOfBoundsException.
Cylvre currently has only one type of loop and that is the ranged for loop. Here is an example of a program that prints the numbers from one to one hundred.
Simple, isn’t it? Cylvre can also do a couple more neat tricks. Like Java, You can omit the curly braces ’{‘ if there is only one statement. Another thing is that if you don’t declare the loop variable, Cylvre implicitly declares it for you!
Another neat thing. Cylvre's loops are self aware. This means that if the start value is less than the end value the loop self increments and vice versa. In the above example, the x
loop incrementally prints form 0 to 100 while the y loop prints decrementally from 100 to 0.
Last updated