0% found this document useful (0 votes)
3 views

Loops in c Program

The document explains loops in C programming, which are used to repeatedly execute code blocks based on given conditions. It details three types of loops: for loops, while loops, and do-while loops, including their syntax and examples. Additionally, it highlights the differences between these loop types.

Uploaded by

lasyakarning
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Loops in c Program

The document explains loops in C programming, which are used to repeatedly execute code blocks based on given conditions. It details three types of loops: for loops, while loops, and do-while loops, including their syntax and examples. Additionally, it highlights the differences between these loop types.

Uploaded by

lasyakarning
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

LOOPS IN C PROGRAM

WHAT IS A LOOP?
• A loop is used to repeatedly execute a
block of code as long as given
condition is true.
• Loops make coding simpler by letting
you repeat actions without writing the
same lines of code over and over
again.
3

TYPES OF LOOPS IN C

1. For Loop
2. While Loop
3. Do-while Loop
FOR

• A for loop is a way to repeat a block of


code a certain number of times. It starts
by setting a value, checks if it should
keep running, and then changes the value
after each run.

SYNTAX:
• For(initialization;condition;increment/
decrement)
• {
• // code block
• }
5

EXAMPLE: FOR LOOP


• for(int i=0; i<=5; i++)
• {
• printf(“%d\n” , i);
• }
6

WHILE
• A While loop repeats a block of code as long
as given condition is true. Before each run it
checks the condition and if its true the code
inside runs. If the condition becomes false
the loop stops.
SYNTAX
• While(condition)
• {
• // code block
• }
7

EXAMPLE:WHILE LOOP
• int i=0;
• while(i<5)
• {
• printf(“%d\n” , i); Click icon to add picture
• i++;
• }
8

DO-WHILE
• Do-while loop is similar to the while loop but it runs the code inside
it at least once no matter what. After the code runs, it checks the
condition if the condition is true the loop repeats if its false the
loop stops
SYNTAX:
• do
• {
• // code block
• }
• while(condition);
9

Click to add picture

EXAMPLE:DO-WHILE LOOP
• int i=0;
• do
• {
• printf(“%d\n” , i);
• i++;
• }
• while(i<5);
10

DIFFERENCE BETWEEN
FOR,DO,DO-WHILE LOOPS
THANK YOU

You might also like