Purpose of Looping
- To execute statements for a specified number of times.
- To use a sequence of values.
- While Loop
- do while Loop
- For loop
It execute one or more statements while the given condition remains true. It is useful when number of iterations is unknown. It is also called entry control or pre test loop.
fig: Flowchart of while loop
do while Loop
do while loops are useful where loop is to be executed at least once. In do while loop condition comes after the body of loop. The loop executes one or more statements while the given condition is true. It is an exit control or post test loop.
Fig: Flowchart to show do while loop
For loop
For loop allows to specify three things about loop in a single line. For loops are used when the number of iterations is known before entering the loop. It is also known as counter controlled loop.
Fig: Flowchart to show execution of for loop
No comments:
Post a Comment
If you have any doubt, let me know...