1 of 11

LOOP(REPITITIVE CONTROL STATEMENT)

MINAKSHI SHARMA

2 of 11

LOOP:-A loop in C is a control structure that allows you to execute a block of code repeatedly, either a fixed number of times or until a certain condition is met.�

​

  • The three main types of loops are for, while, and do while.
  • The for loop is used when the number of iterations is known in advance.
  • The while loop runs as long as the condition remains true, and do while runs at least once.

Key Components of a Loop

  1. Initialization: Sets up a starting point (e.g., int i = 0).
  2. Condition: Determines whether the loop continues.
  3. Increment/Decrement: Updates the loop variable after each iteration.

​

3 of 11

FOR LOOP

  • It is a entry controlled loop
  • in C it is a control structure used to repeat a block of code a specific number of times. It is commonly used when the number of iterations is known before the loop starts.
  • Syntax:-
  • for (initialization; condition; update value)
  • {
  • // Code to execute
  • }

4 of 11

FOR LOOP

  • Example:-Program to display counting upto ten
  • #include <stdio.h>
  • int main()
  • {
  • Int I;
  • for (i=1; i <= 5; i++)
  • {
  • printf("%d\n", i); // Prints numbers from 1 to 5
  • }
  • return 0;
  • }

Output

1

2

3

4

5

5 of 11

while LOOP

  • It is a entry controlled loop
  • in C it is a control structure used to repeat a block of code a specific number of times. It is commonly used when the number of iterations is known before the loop starts.
  • Syntax:-
  • initialization;
  • while (condition)
  • {
  • // Code to execute
  • Update value;
  • }

6 of 11

While LOOP

  • Example:-Program to display counting upto ten
  • #include <stdio.h>
  • int main()
  • {
  • Int i=1;
  • while (i <= 5)
  • {
  • printf("%d\n", i); // Prints numbers from 1 to 5
  • i++;
  • }
  • return 0;
  • }

Output

1

2

3

4

5

7 of 11

Do while LOOP

  • It is a exit controlled loop
  • executes the block of code at least once before checking the condition. This ensures that the body of the loop is executed at least once, regardless of whether the condition is true or false initially.
  • Syntax:-
  • initialization;
  • do
  • {
  • // Code to execute
  • Update value;
  • }while(condition);

​

  • Condition: The condition is evaluated after the loop's body is executed. If the condition is true, the loop repeats; if the condition is false, the loop terminates.

8 of 11

While LOOP

  • Example:-Program to display counting upto ten
  • #include <stdio.h>
  • int main()
  • {
  • Int i=1;
  • do
  • {
  • printf("%d\n", i); // Prints numbers from 1 to 5
  • i++;
  • } while(i<=5);
  • return 0;
  • }

Output

1

2

3

4

5

9 of 11

Difference between for,while,do while loop

10 of 11

Summary:

  • for loop Best for when you know the number of iterations ahead of time or when you can express initialization, condition checking, and update in a single line.
  • while loop Best when you don't know the number of iterations ahead of time, and you need to continue looping as long as a condition holds true.
  • do while loop Best when you want to guarantee the loop runs at least once, regardless of the condition.

​

11 of 11

THANKS