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:

  1. for loop
  2. while loop
  3. do…while loop

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

{

printf(” hello”);

}

For example: for(i=0;i<=10;i++) // using initialization condition and increment

{

printf(“A”);

}

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.

For example:

i=1;

while(i<=10){

printf(“%d\n”,i);

i++;

}

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;

do{

printf(“%d”,i);

i++;

}while(i<=10);

return 0;

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.

Edusera
Logo
Open chat
1
Scan the code
Hello!👋
Can we help you?