×
Menu
Index

FOR..TO..NEXT Keywords

 
Usage:
FOR var = start TO end
    statements
NEXT
 
Description:
Use a FOR loop to execute a block of statements a specified number of times.
 
Initially, var is set to the value specified by start. Then, each time the block of statements are executed, var is incremented. When var is greater than end, execution continues on the next statement after the NEXT keyword. If end is less than start, the block of statements is never executed.
 
NOTE: The start and end values are evaluated only once and the resulting values are cached. So, for example, if the loop modifies values used in the end expression, this will not alter the number of times the block of statements is executed.
 
NOTE 2: Unlike the BASIC language, the name of the variable is not required nor allowed after the NEXT statement.
 
Example:
sub main()
   for i = 1 to 10
      printl("This is line ", i)
   next
end sub