MFP language while, loop, do, until, for, next statements:
While and loop, do and until, and for and next are three pairs of looping statements in MFP. They should be used in the following way:
While condition
......
Loop
Do
......
Until condition
For variable var = from_value to to_value step step_value
......
Next
where condition is an expression which has boolean value (or can be converted to boolean value). Var is the name of for statement's index variable. From_value is the initial value of var, step_value is how much var increases each time. Note that step_value can be negative. To_value is the destination value of var variable. Var variable stops to change if it is beyond to_value. Note that if var is defined before, the variable keyword following for can be ignored. The following code is an example of for block. Note that when for statment's index variable's value equals to_value, statments inside for block are still executed. Only if index variable's value is beyond to_value the for loop finishes.
variable idx for idx = 1 to -1 step -2 print_line("idx == " + idx) next
By running the above code, the output is
idx == 1
idx == -1
Note that all the three looping blocks support break and continue statement. When break is hit, MFP jumps out the current inner-most looping block. When continue is hit, MFP ignores the following statements in the inner-most looping block and goes back to the beginning of the looping block.