Flowchart of for Loop in C++
Execution Flow of a for Loop
- Control falls into the for loop. Initialization is done.
- The flow jumps to Condition.
- Condition is tested.
- If the Condition yields true, the flow goes into the Body.
- If the Condition yields false, the flow goes outside the loop.
- The statements inside the body of the loop get executed.
- The flow goes to the update.
- Updation takes place and the flow goes to Step 3 again.
- The for loop has ended and the flow has gone outside.
for Loop in C++
In C++, for loop is an entry-controlled loop that is used to execute a block of code repeatedly for the specified range of values. Basically, for loop allows you to repeat a set of instructions for a specific number of iterations.
for loop is generally preferred over while and do-while loops in case the number of iterations is known beforehand.
Contact Us