Difference between revisions of "Loop Icon Properties"

From Flowcode Help
Jump to navigationJump to search
(Linked new video)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{| style="margin:auto; text-align:center;"
+
[[File:iconLoop.png|border]]
|-
+
 
|[[File:Btn_Loop.gif|border]]
+
Loop icons are used to repeat a task until specified conditions are fulfilled, or to perform the loop a set number of times.
| width="50px" |→
+
 
|[[File:Gen_Loop_Flowchart_Icon.png]]
 
|width="50px" |→
 
|[[File:Properties-loop.png]]
 
|}
 
  
<br>
 
 
==Old Versions==
 
==Old Versions==
 
This page is current for Flowcode v11 and later. Earlier versions can be found below:
 
This page is current for Flowcode v11 and later. Earlier versions can be found below:
Line 21: Line 16:
 
|}
 
|}
  
<br>
 
  
 +
==Details==
 +
{| style="margin:0px; text-align:center;"
 +
|-
 +
|[[File:iconLoop.png|border]]
 +
| width="50px" |&rarr;
 +
|[[File:Gen_Loop_Flowchart_Icon.png]]
 +
|width="50px" |&rarr;
 +
|[[File:Properties-loop.png]]
 +
|}
 +
 +
==Loop types==
 +
There are several types of loop as explained below.
 +
 +
===Loop forever===
 +
Creates an infinite loop where the icons between the start and end of this loop icon are repeated forever. Many embedded programs require an infinite loop because the code running in the microcontroller will never stop.  In versions of Flowcode prior to v11, a condition "While 1" would have been used instead to create an infinite loop.
  
==Introduction==
+
===Loop while===
Loop icons are used to repeat a task until specified conditions are fulfilled, or to perform the loop a set number of times.
+
A "while" loop will repeat the icons if the test in the "expression" box is true. This expression can be tested at the start or at the end of the loop and it is at this point that the program decides to continue or abort the loop.
 +
 
 +
===Loop until===
 +
An "until" loop is similar to the "while" loop, but this time the loop will repeat until the test in the "expression" box becomes true. Again, this can be tested at the beginning or the end of the loop.
 +
 
 +
===Loop count===
 +
This allows a loop to be repeated a set number of times. The number of times to repeat is entered in the "count" box. Note that this value will usually be a constant or a literal value (e.g. "5").
 +
 
 +
An internal counter will be set to zero when the loop first begins and will be automatically incremented at the end of each loop iteration. At the beginning of each loop, this internal counter will be checked to see if it is less than the value of the "count", and if it is not then the loop will be aborted.
  
Note that you will need to add [[Calculation Icon Properties|calculation icons]] that modify the variables used for the condition in order for the condition to be fulfilled.
+
This internal counter can be set to an existing variable instead using the '''Count using a variable''' option. This will expose the number of iterations around the loop to the code within the loop start and end icons. This variable will show a value of "0" during the first loop iteration, "1" in the second loop iteration, etc.
  
  
 +
==Properties==
 
'''Display Name'''
 
'''Display Name'''
 
   
 
   
Line 35: Line 53:
  
  
'''Loop forever'''
+
'''Expression'''
 
 
Creates an infinite loop where the icons between the start and end of this loop icon are repeated forever. Many embedded programs require an infinite loop because the code running in the microcontroller will never stop.  In versions of Flowcode prior to v11, a condition "While 1" would have been used instead to create an infinite loop.
 
  
 +
The expression used to determine if the loop should continue or end. This is used by "while" and "until" versions of the loop command.
  
'''Loop while'''
+
For a "while" loop, this loops the program while the specified condition is true.
  
Loops the program until the specified condition becomes true. Enter the conditions which will fulfil the loop.
+
For an "until" loop, this loops the program until the specified condition becomes true.
  
(Setting the test condition to something that is always true will make the loop repeat forever e.g. While 1)
+
The expression is tested at the beginning or the end of the loop.
  
  
Line 54: Line 71:
 
'''Test the loop at the:'''
 
'''Test the loop at the:'''
  
Select whether you wish the loop to be tested at the start or at the end of the loop.
+
Select whether you wish the loop's expression to be tested at the start or at the end of the loop. Testing at the end of the loop means that the code within the loop is guaranteed to execute at least once.
 
 
Can be set to check the condition at the start of the loop or at the end of the loop.
 
  
  
 
'''Loop count'''
 
'''Loop count'''
  
Sets the loop to loop through a set number of times.
+
Sets the loop to loop through a set number of iterations. The value should usually be a whole number between 1 and 99999999.
  
Count must be a whole number between 1 and 99999999.
+
Note that a variable can be used for the "count" rather than a constant value. But be aware because changing the value of this variable within the loop could cause odd behaviour and make your program's execution difficult to predict.
  
  
 
'''Count using a variable'''
 
'''Count using a variable'''
  
Allows one of your existing variables to be used as the count variable.  
+
Allows an existing variable to be used as the count variable. When active, this resets the count variable to 0 when the loop first begins and automatically increments the variable at the end of each loop iteration. It is best that the value of this variable should not be altered within the loop by user code, otherwise the loop may behave unexpectedly.
 
 
When active this automatically resets the count variable to 0 and increments the variable for you to give you the correct number of loop iterations.
 
  
  
 
==Video==
 
==Video==
 
See the [http://www.flowcode.co.uk/videos/videoview/?name=The+Loop+icon&id=local&wiki=Loop_Icon_Properties Loop icon video] to see how this icon is used in a project.
 
See the [http://www.flowcode.co.uk/videos/videoview/?name=The+Loop+icon&id=local&wiki=Loop_Icon_Properties Loop icon video] to see how this icon is used in a project.

Latest revision as of 16:28, 11 June 2026

IconLoop.png

Loop icons are used to repeat a task until specified conditions are fulfilled, or to perform the loop a set number of times.


Old Versions

This page is current for Flowcode v11 and later. Earlier versions can be found below:

Flowcode v10
Flowcode v9
Flowcode v8


Details

IconLoop.png Gen Loop Flowchart Icon.png Properties-loop.png

Loop types

There are several types of loop as explained below.

Loop forever

Creates an infinite loop where the icons between the start and end of this loop icon are repeated forever. Many embedded programs require an infinite loop because the code running in the microcontroller will never stop. In versions of Flowcode prior to v11, a condition "While 1" would have been used instead to create an infinite loop.

Loop while

A "while" loop will repeat the icons if the test in the "expression" box is true. This expression can be tested at the start or at the end of the loop and it is at this point that the program decides to continue or abort the loop.

Loop until

An "until" loop is similar to the "while" loop, but this time the loop will repeat until the test in the "expression" box becomes true. Again, this can be tested at the beginning or the end of the loop.

Loop count

This allows a loop to be repeated a set number of times. The number of times to repeat is entered in the "count" box. Note that this value will usually be a constant or a literal value (e.g. "5").

An internal counter will be set to zero when the loop first begins and will be automatically incremented at the end of each loop iteration. At the beginning of each loop, this internal counter will be checked to see if it is less than the value of the "count", and if it is not then the loop will be aborted.

This internal counter can be set to an existing variable instead using the Count using a variable option. This will expose the number of iterations around the loop to the code within the loop start and end icons. This variable will show a value of "0" during the first loop iteration, "1" in the second loop iteration, etc.


Properties

Display Name

The name of the icon that appears on the flowchart.


Expression

The expression used to determine if the loop should continue or end. This is used by "while" and "until" versions of the loop command.

For a "while" loop, this loops the program while the specified condition is true.

For an "until" loop, this loops the program until the specified condition becomes true.

The expression is tested at the beginning or the end of the loop.


Variables Arrow

Clicking on the down arrow brings up the variables dialog window allowing you to select an existing variable or to create a new one.


Test the loop at the:

Select whether you wish the loop's expression to be tested at the start or at the end of the loop. Testing at the end of the loop means that the code within the loop is guaranteed to execute at least once.


Loop count

Sets the loop to loop through a set number of iterations. The value should usually be a whole number between 1 and 99999999.

Note that a variable can be used for the "count" rather than a constant value. But be aware because changing the value of this variable within the loop could cause odd behaviour and make your program's execution difficult to predict.


Count using a variable

Allows an existing variable to be used as the count variable. When active, this resets the count variable to 0 when the loop first begins and automatically increments the variable at the end of each loop iteration. It is best that the value of this variable should not be altered within the loop by user code, otherwise the loop may behave unexpectedly.


Video

See the Loop icon video to see how this icon is used in a project.