for loop

View


A condition using loop variable is specified with for-statement. If the condition is FALSE then the statements inside while block will be skipped, If the condition is TRUE then the statements inside while block will be executed again and again until the condition becomes FALSE.

 

The difference between while loop and for loop is just the difference of their syntax, otherwise, logically they works in the same way.

 

In for loop, initialization of loop variable, condition using loop variable and Increment/decrement of loop variable are specified in the same line whereas in while-loop, they are specified in different lines as shown above.

 

Example- WAP in C to print your name 10 times

Flowchart-

Same as that of while-loop


Last modified: Tuesday, 21 September 2021, 9:45 AM