There may be a situation when we need to execute a block of code several number of times, and is often referred to as a loop.
Every Language has very flexible three looping mechanisms. You can use one of the following three loops:
A for loop is useful when you know how many times a task is to be repeated.
Every Language has very flexible three looping mechanisms. You can use one of the following three loops:
- For Loop
- While Loop
- Do .. While Loop
The for Loop:
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.A for loop is useful when you know how many times a task is to be repeated.
Syntax:
for(initialization; Boolean_expression; update) { //Statements }
Here is the flow of control in a for loop:
|
statement executed once when beginning loop |
---|---|
|
if the test evaluates to true, the statements execute |
|
executes at the end of each iteration |
|
collection of statements executed each time through the loop |
0 comments:
Post a Comment