WHAT ARE LOOPS?
The loops are needed to execute a block of code many of the times. In this, basically the statements are executed sequentially which means the first statement in a function is executed first than the second statement and so on. The loops are used to execute a single statement or the group of statements multiple times.
SOME OF THE LOOPS IN C++ ARE
- For loop
- While loop
- Do-while loop
LET US UNDERSTAND THESE LOOPS IN BRIEFLY
The for loop is used as a repetition control statement that allows you to write a loop that will execute a specific number of times. The for loop is used to execute the block of statements again and again till the condition returns false. In for loop, the statement is executed till the Boolean condition is not true, as the condition is true it will terminate the loop. The for loop consists of three parts first is the initialization, second is the condition and third is increment or decrement statement.
THE FOR LOOP SYNTAX IS LIKE THIS:
for(initialization; condition; increment or decrement )