0% found this document useful (0 votes)
70 views12 pages

Loops in C Programming

This document provides an overview of loops in C programming. It discusses the main types of loops: for loops, while loops, and do-while loops. A for loop allows the user to initialize a variable, test a condition, and increment/decrement the variable in the header. A while loop checks a condition and repeats a block of code while the condition is true. A do-while loop is similar but checks the condition after running the code block once. Examples are given of for and while loops to print numbers from 1 to 5. The for loop initializes a counter variable i, tests if i is less than or equal to 5, and increments i each iteration. The while loop initializes i, tests

Uploaded by

sukriti rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views12 pages

Loops in C Programming

This document provides an overview of loops in C programming. It discusses the main types of loops: for loops, while loops, and do-while loops. A for loop allows the user to initialize a variable, test a condition, and increment/decrement the variable in the header. A while loop checks a condition and repeats a block of code while the condition is true. A do-while loop is similar but checks the condition after running the code block once. Examples are given of for and while loops to print numbers from 1 to 5. The for loop initializes a counter variable i, tests if i is less than or equal to 5, and increments i each iteration. The while loop initializes i, tests

Uploaded by

sukriti rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Loops in C Programming

-----------------------------------
---------
Presentation on Loop
By:-
SUKRITI RAI
(B.Sc. 1st year )
UNDER THE SUPERVISION OF
Er. Sachin Jaiswal
Introduction to Loops
* A loop is defined as a block of
statements, which are repeatedly executed
for a certain number of times
* A loop executes the sequence of statement
many times until the stated condition
becomes false.
A loop consists of two parts , a body of a
loop and a control statement
Types of Loops
In Pre – Test Loop, condition is checked before
the beginning of each iteration. If condition is
TRUE repetition is performed, if it is FALSE
repetition is not performed

“Pre – Test loop is implemented using


‘while’ statement”
* In Post – Test Loop, first the block of statements
to be repeat is executed then condition will be
tested
*That means in Post – Test Loop, condition is
checked after executing the repeating
statements, if the condition is TRUE it repeat the
statements again, if it is FALSE repetition is not
performed

“Post – Test loop is implemented using ‘do -


while’ statement”
FOR LOOP -:
---------------
syntax
for(initialization ; condition ; increment/decrement)
{
statement();
}

The initialization expression set the initial value of the loop control variable.

The condition test the value of the loop control variable.

The increment or decrement update the loop control variable.


Program of For Loop :-
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=1;i<=5;i++)
{
printf(“Hello\n”);
}
getch();
}
Output of the above program
Hello
Hello
Hello
Hello
Hello
While Loop:-
Syntax
While (condition)
{
statement();
}

In the while loop , when the condition is true , then the while loop’s statement will
be executed , otherwise not.
The statement is repeated as long as the repetition condition is true
Comparing For and While Loop:---
Program of While Loop:-
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
while(i<=5)
{
printf(“%d \n” , i);
i++;
}
getch();
}

Output of the above program------


1
2
3
4
5
Reference:-
[1]. E Balaguruswamy, “Programming in ANSI C”, Third edition,

[2].Google.com

[3] PDF notes provided by Sachin Sir …………………….


Thank You !
Have a Nice day……

You might also like