Differences

This shows you the differences between two versions of the page.

Link to this comparison view

fornext [2019/05/07 13:25]
neils created
fornext [2020/02/21 14:44] (current)
neils
Line 3: Line 3:
 Syntax: Syntax:
  
- for <byte or int variable> = <byte or int expression1> to <byte or int expression2>+ for <byte or int variable> = <byte or int initial_value> to <byte or int end_value[step <byte or int step>]
  [statements...]  [statements...]
- next <variable>+ next [<variable>]
   
-The ''FOR ... NEXT'' construct will assign the result of ''expression1'' to the given variable, then iterate the variable until it reaches the value of  ''expression2'', executing the commands between ''FOR'' and ''NEXT''  as many times as necessary. ''FOR ... NEXT'' constructs can be nested.+The ''FOR ... NEXT'' construct will assign the result of ''initial_value'' to the given variable, then iterate the variable until it reaches the value of  ''end_value'', executing the commands between ''FOR'' and ''NEXT''  as many times as necessary. 
  
-**Note #1**: the value of ''expression2'' is evaluated only oncebefore starting the loop.+If ''step'' is provided, the variable will be incremented or decremented with ''step''. ''step'' defaults to 1 otherwise.
  
-**Note #2**: it is not possible to omit the variable name after the ''NEXT'' statement.+The types of ''initial_value'', ''end_value'' and ''step'' must match that of  ''variable''
 + 
 +''FOR ... NEXT'' constructs can be nested. 
 + 
 +**Note #1**: ''end_value'' is evaluated only once, before starting the loop. 
 + 
 +**Note #2**: the variable name after the ''NEXT'' statement is not mandatory since version 2.3.
  
 **Note #3**: the runtime library will not check the consistency of your ''FOR ... NEXT'' blocks. If there is a ''NEXT'' without ''FOR'', for example, the program will likely break. **Note #3**: the runtime library will not check the consistency of your ''FOR ... NEXT'' blocks. If there is a ''NEXT'' without ''FOR'', for example, the program will likely break.