For Each...Next: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
Created page with "FOR EACH ''element'' IN ''group'' <br /> :::[''statements''] <br /> ::::[EXIT FOR] <br /> :::[''statements''] <br /> NEXT [''element''] '''Description''' FOR EACH...NEXT rep..."
 
Brendon (talk | contribs)
No edit summary
Line 1: Line 1:
FOR EACH ''element'' IN ''group'' <br />
For Each ''element'' In ''group'' <br />
:::[''statements''] <br />
:::[''statements''] <br />
::::[EXIT FOR] <br />
::::[Exit For] <br />
:::[''statements''] <br />
:::[''statements''] <br />
NEXT [''element'']
Next [''element'']


'''Description'''
== Description ==


FOR EACH...NEXT repeats a group of statements, once for each element in an array or collection. The required parameter, ''element'', is a variable name that can be used to reference the current element. The required parameter, ''group'', is the name of an array, or collection of objects. The optional component, ''statements'', will be executed as the body of the loop. Any number of optional EXIT FOR statements can be used to exit a loop before it is finished. FOR EACH...NEXT statements can be nested, and any EXIT FOR statements in a nested loop transfer execution to one level above the loop where the EXIT FOR occurs.
For Each...Next repeats a group of statements, once for each element in an array or collection. The required parameter, ''element'', is a variable name that can be used to reference the current element. The required parameter, ''group'', is the name of an array, or collection of objects. The optional component, ''statements'', will be executed as the body of the loop. Any number of optional Exit For statements can be used to exit a loop before it is finished. For Each...Next statements can be nested, and any Exit For statements in a nested loop transfer execution to one level above the loop where the Exit For occurs.


Note: FOR EACH...NEXT will not work with arrays of user-defined types.
Note: For Each...Next will not work with arrays of user-defined types.


'''Example'''
== Example ==


<pre>
<pre>
REM FOR EACH...NEXT Example
Rem For Each...Next Example
DIM School
Dim School
School = ARRAY("Principal","Mr. Garrison", _
School = Array("Principal","Mr. Garrison", _
   "Chef")
   "Chef")
FOR EACH Employee IN School
For Each Employee In School
   PRINT "School employee:", Employee
   Print "School employee:", Employee
NEXT
Next
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 31: Line 31:
</pre>
</pre>


'''Related Items'''
== Related Items ==


[[do...loop|DO...LOOP]], [[exit|EXIT]], [[for...next|FOR...NEXT]], [[while...wend|WHILE...WEND]]
[[do...loop|DO...LOOP]], [[exit|EXIT]], [[for...next|FOR...NEXT]], [[while...wend|WHILE...WEND]]
[[Category:Language Reference]]

Revision as of 01:12, 17 August 2012

For Each element In group

[statements]
[Exit For]
[statements]

Next [element]

Description

For Each...Next repeats a group of statements, once for each element in an array or collection. The required parameter, element, is a variable name that can be used to reference the current element. The required parameter, group, is the name of an array, or collection of objects. The optional component, statements, will be executed as the body of the loop. Any number of optional Exit For statements can be used to exit a loop before it is finished. For Each...Next statements can be nested, and any Exit For statements in a nested loop transfer execution to one level above the loop where the Exit For occurs.

Note: For Each...Next will not work with arrays of user-defined types.

Example

Rem For Each...Next Example
Dim School
School = Array("Principal","Mr. Garrison", _
  "Chef")
For Each Employee In School
  Print "School employee:", Employee
Next

Output

School employee:     Principal
School employee:     Mr. Garrison
School employee:     Chef

Related Items

DO...LOOP, EXIT, FOR...NEXT, WHILE...WEND