For Loops (definite loop)
A For loop is used when we need to execute a set of instructions more than once, and we know how many times we will have to do it.
Common examples of this situation are where we are trying to do something a certain number of times (i.e. get 5 numbers from the user and find their average) or if the user wants to repeat some actions again but only so many times (i.e. letting a user enter their password, but it locks them out after the third try).
To add a For Loop to a Flowgorithm program
- Ensure that you have already declared the loop variable Note that even if you have assigned the loop variable a value previously, it will automatically be reset to the starting value of the range
- Make sure you declare any variables that will be needed before you start the loop
- Click on the vertical line on the flowchart and choose the type of loop
- Enter all the properties for the loop
- We don’t have to update our loop variable because this is done automatically
Properties of the For loop are set by clicking on the For shape
- Variable – the name of your loop variable
- Start value – number of start from
- End value – number to stop at
- Direction – is the loop variable increasing or decreasing
- Step By: How much should the loop variable be incremented each time