Loops in c
programming…
B
y : Rahul
Branch : CSE
Roll no. : 9526/22
CONTENTS
●Introduction
●What are loops
●Types of loops in C
●For loop
●While loop
●Do-while loop
●Conclusion
INTRODUCTION
For Example, You want to print your name i.e. Rahul, 5
times then here is a simple program to do the same.
#include<stdio.h>
#include<conio.h>
void main() {
printf(“Rahul”);
printf(“Rahul”);
printf(“Rahul”);
printf(“Rahul”);
printf(“Rahul”);
}
What is a loop
A loop statement allows us to execute a statement or a group of
statements multiple times based on a condition.
Loop statements are used to repeat the execution of statement or blocks.
Types of Loops in C
●For loop
●While loop
●Do while loop
For Loop
For loop is used to iterate the statements or a part of the program several times.
Syntax:-
for(variable initialize; condition; increment/decrement)
{
statement
}
Example:-
int main()
{ OUTPUT:- value is =
int i; 1
for(i=1; i<=3; i++) 2
{ 3
printf(“value is =%dn”, i);
}
}
While Loop
It is an entry control loop, so condition is tested before each iteration to decide whether to
continue or terminate the loop.
Syntax:-
Variable initialize;
While(condition)
{
Statement;
Increment/decrement;
}
Example:- OUTPUT:-
int main() { 1
int i; 2
i=1; 3
while(i<=3)
{ printf(“%dn”, i);
i++; }
}
Do while Loop
It is an exit control loop, condition is checked after one time execution of the body of the loop.
Syntax:-
Variable initialize;
do {
Statement;
Increment/Decrement; }
while(condition);
Example:- OUTPUT:- value is =
int main() { 1
int i; 2
i=1; 3
do {
printf(“ value is = %dn”, i);
i++; }
while(i<=3);
}
CONCLUSIONS
loops are very important in any
programming language as they
allow us to reduce the number
of lines in a code, making our
code more readable and
efficient.
Thankyou…

C PROGRAMMING. Pptx new required for anyone.

  • 1.
    Loops in c programming… B y: Rahul Branch : CSE Roll no. : 9526/22
  • 2.
    CONTENTS ●Introduction ●What are loops ●Typesof loops in C ●For loop ●While loop ●Do-while loop ●Conclusion
  • 3.
    INTRODUCTION For Example, Youwant to print your name i.e. Rahul, 5 times then here is a simple program to do the same. #include<stdio.h> #include<conio.h> void main() { printf(“Rahul”); printf(“Rahul”); printf(“Rahul”); printf(“Rahul”); printf(“Rahul”); }
  • 4.
    What is aloop A loop statement allows us to execute a statement or a group of statements multiple times based on a condition. Loop statements are used to repeat the execution of statement or blocks.
  • 5.
    Types of Loopsin C ●For loop ●While loop ●Do while loop
  • 6.
    For Loop For loopis used to iterate the statements or a part of the program several times. Syntax:- for(variable initialize; condition; increment/decrement) { statement } Example:- int main() { OUTPUT:- value is = int i; 1 for(i=1; i<=3; i++) 2 { 3 printf(“value is =%dn”, i); } }
  • 7.
    While Loop It isan entry control loop, so condition is tested before each iteration to decide whether to continue or terminate the loop. Syntax:- Variable initialize; While(condition) { Statement; Increment/decrement; } Example:- OUTPUT:- int main() { 1 int i; 2 i=1; 3 while(i<=3) { printf(“%dn”, i); i++; } }
  • 8.
    Do while Loop Itis an exit control loop, condition is checked after one time execution of the body of the loop. Syntax:- Variable initialize; do { Statement; Increment/Decrement; } while(condition); Example:- OUTPUT:- value is = int main() { 1 int i; 2 i=1; 3 do { printf(“ value is = %dn”, i); i++; } while(i<=3); }
  • 9.
    CONCLUSIONS loops are veryimportant in any programming language as they allow us to reduce the number of lines in a code, making our code more readable and efficient.
  • 10.