What is Loop Control Statement?
Loop control statement is use for repetition purpose. When we want to repeat the code we will use loop control statements. So that we will not need to write the block of code again and again. For example, if we want to repeat the number 10 times then we will use for loop using condition.
There are three loop control statements:
for loop: When we want repeat particular things then we will use for loop. We can use for loop in two ways: using range and conditions.
For example: for i in range(9) // using range
For example: for(i=0;i<=10;i++) // using initialization condition and increment
Output: A A A A A A A A A A A
While loop: while loop allows to repeat the block of code until a condition is met. when the condion is met compiler will stop the execution.
do…while loop: A do…while loop is similar to while loop with only one exception that it executes the statements inside the body of do-while before checking the condition.
For example: int i=1;
Output: 1 2 3 4 5 6 7 8 9 10
Advantage of loop control statements:
It saves our time of writing the code again and again.
We can execute multiple program of different types in less time.