Explain me about for loop statement with some suitable example along with its flow chart.
What is for loop statement?
583
21-Jan-2020
Nishi Tiwari
21-Jan-2020For loop is useful to execute block of statement until the specified condition evaluates to true.
For loop is used to iterate and execute the block of statement when we know the number of times the block of statement will execute.
Syntax
In above syntax, we observed initialization, condition, iteration separated by semicolon (;).
In initialization, variable will be initialized with some value and it will execute only one time at the starting of for loop.
In condition part condition will be checked and it will return either true or false. If condition evaluates true then body of for loop will be executed otherwise not.
If condition evaluates to true, body of for loop will be executed. Then iteration part will be evaluated and it will increase or decrease the variable according to the requirement. And condition will be checked again.
If condition evaluates to false then for loop will stops its execution and control comes out of loop.
Output:-
Flow chart of For Loop