Control structures
If conditional
In melon the if statement is similar to most imperative programming languages,
its syntax is:
The statement is usually a block or a function call/assignment statement:
else/else if also work as usual:
While loop
While loops execute a statement while an expression is true, in melon they follow the syntax convention of most imperative languages:
As in the if conditional, the statement is usually a block or a function call/assignment statement:
For-in loops
The for loop in melon is bit different from the one in most imperative languages and it's more like a for-each loop. The for loop in melon iterates over a an Iterator value, assigning each element to a variable in succession.
For example you can use a for loop to iterate over Range values:
The code above will print numbers from 0 to 9, the for loop will get the iterator from the 0..10 range value and put the next value in the i variable. On the next step of the loop, i will contain the next value in the iterator, i will change on every iteration until the iterator returns a value with its done property set to true. See Iterator for an in-depth explanation.