User Tools

Site Tools


en:foreach

Differences

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

Link to this comparison view

Next revision
Previous revision
en:foreach [2020/04/21 19:10]
admin created
en:foreach [2020/04/26 22:32] (current)
admin
Line 1: Line 1:
-===== For / Next (Statement) =====+===== For Each / Next (Statement) =====
 ==== Format ==== ==== Format ====
-**for** [[variables|variable]] =  [[numericexpressions|start_expression]] **to** [[numericexpressions|stop_expression]] [ **step** [[numericexpressions|step_expression]] ] \\+**for each** [[variables|variable]] **in** [[Arrays|array]] \\ 
 +(tab)[[programsyntax|statement(s)]]\\ 
 +**next** [[variables|variable]] 
 + 
 +**for each** [[variables|key]] **in** [[Maps|map]] \\ 
 +(tab)[[programsyntax|statement(s)]]\\ 
 +**next** [[variables|variable]] 
 + 
 + 
 +**for each** [[variables|key]] **%%->%%** [[variables|value]] **in** [[Maps|map]] \\
 (tab)[[programsyntax|statement(s)]]\\ (tab)[[programsyntax|statement(s)]]\\
 **next** [[variables|variable]] **next** [[variables|variable]]
Line 7: Line 16:
 ==== Description ==== ==== Description ====
  
-The FOR and NEXT commands are used in conjunction to execute command or group of commands specified number of timesWhen the FOR command is first encountered, the variable is set to [[numericexpressions|start_expression]].\\ +The FOREACH and NEXT commands are used to loop through the elementf of list, an array, or a maap Each element will be returned in the variable. 
-After each NEXT command, variable is incremented by 1 (the default), or by [[numericexpressions|step_expression]] if the optional STEP is used, until the variable is greater than [[numericexpressions|stop_expression]] for positive step values, or less than [[numericexpressions|stop_expression]] for negative step values.+ 
 +If the array is two dimensional it will be traversed through the columns of row one then row two...
  
 ==== Example ==== ==== Example ====
 <code> <code>
-for i to 10+for each in {1,2,3,4} 
 + print i 
 +next i 
 +x = {'a','b','c'
 +for each i in x
  print i  print i
 next i next i
- 
-print "after the for " + i 
 </code> </code>
 displays displays
Line 24: Line 36:
 3 3
 4 4
-5 +a 
-6 +b 
-+c
-+
-+
-10 +
-after the for 11+
 </code> </code>
  
 ==== See Also ==== ==== See Also ====
 {{page>en:start#Program Control&noheader}} {{page>en:start#Program Control&noheader}}
 +
 +==== History ==== 
 +|2.0.0.0|New To Version|
en/foreach.1587517823.txt.gz · Last modified: 2020/04/21 19:10 by admin