Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
11 views
While Loop
selectionstructure
Uploaded by
Mary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save While Loop For Later
Download
Save
Save While Loop For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
11 views
While Loop
selectionstructure
Uploaded by
Mary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save While Loop For Later
Carousel Previous
Carousel Next
Save
Save While Loop For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 5
Search
Fullscreen
5/14/24, 8:03 AM while loop in C - GeeksforGeeks while loop in C Last Updated : 07 May, 2023 The while Loop is an entry-controlled loop in C programming language. This loop can be used to iterate a part of code while the given condition remains true. Syntax The while loop syntax is as follows: while (test expression) { // body consisting of multiple statements Example The below example shows how to use a while loop in a C program Cc // C program to demonstrate while loop #include
int main() { // Initialization of loop variable int i = 05 // setting test expression as (i < 5), means the loop 7/ will execute till i is less than 5 while (i <5) { // loop statements printf ("GeeksforGeeks\n"); // updating the loop variable iets + return @; hntps:nww.geekstorgecks orgicawhileloop/7eef=bp 185/14/24, 8:03 AM while loop in C - GeeksforGeeks Output GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks while Loop Structure The while loop works by following a very structured top-down approach that can be divided into the following parts: LT is not part of while loop syntax but it is essential when we are using some variable in the test alization: In this step, we initialize the loop variable to some initial value. Initialization expression 2. Conditional Statement: This is one of the most crucial steps as it decides whether the block in the while loop code will execute. The while loop body will be executed if and only the test condition defined in the conditional statement is true. hntps:inww.geekstorgecks orgicanhiteloopi7eef=Ibp 218sare, 503 aM vii loo in C= GeestorGeoks 3. Body: It is the actual set of statements that will be executed till the specified condition is true. It is generally enclosed inside { } braces. 4. Updation: It is an expression that updates the value of the loop variable in each iteration. It is also not part of the syntax but we have to define it explicitly in the body of the loop. Flowchart of while loop in C While loop Start Test Condition? False Execute loop body While loop ends Working of while Loop We can understand the working of the while loop by looking at the above flowchart: hntps:inww.geekstorgecks orgicanhiteloopi7eef=Ibp 385/14/24, 8:03 AM while loop in C - GeeksforGeeks 1. STEP 1: When the program first comes to the loop, the test condition will be evaluated. 2. STEP 2A: If the test condition is false, the body of the loop will be skipped program will continue. 3. STEP 2B: If the expression evaluates to true, the body of the loop will be executed. 4, STEP 3: Afier executing the body, the program control will go to STEP 1. This process will continue till the test expression is true. Infinite while loop An infinite while loop is created when the given condition is always true. It is encountered by programmers in when: + The test condition is incorrect. + Updation statement not present. Example // © program to demonstrate an infinite while loop #include
int main() { // Initialization int gfgl = 1; int gfg2 = 1; // ‘gfgi' is the Check/Test statement, which means that // the while loop will iterate till the conditions // satiate while (gfgi < 10) ¢ // *efg2' is the body statements efg2 = gfg2 + 15 printf("GeeksforGeeks to Infinity"); + // Return statement to tell that everything executed hntps:nww-geekstorgecks orgic-nhiteloop/7eef=bp 48sr1424, 803M ile loop in C- GecktorGacks // safely return @; hntps:inww.geekstorgecks orgicanhiteloopi7eef=Ibp 58
You might also like
C - While Loop
PDF
No ratings yet
C - While Loop
7 pages
Loop Statement So in c Programming
PDF
No ratings yet
Loop Statement So in c Programming
20 pages
While Loop
PDF
No ratings yet
While Loop
3 pages
Unit-2 Loops in C Programming
PDF
No ratings yet
Unit-2 Loops in C Programming
21 pages
While Loop
PDF
No ratings yet
While Loop
9 pages
Cse 122
PDF
No ratings yet
Cse 122
3 pages
Chap 3 LOOPS IN C
PDF
No ratings yet
Chap 3 LOOPS IN C
10 pages
loops
PDF
No ratings yet
loops
8 pages
C Loops
PDF
No ratings yet
C Loops
10 pages
C Programming UNIT 3.1 Loops
PDF
No ratings yet
C Programming UNIT 3.1 Loops
32 pages
Lecture 1 Looping Statements
PDF
No ratings yet
Lecture 1 Looping Statements
84 pages
Lect10-Loop-in-C
PDF
No ratings yet
Lect10-Loop-in-C
8 pages
14 Making Decisions in "C"
PDF
No ratings yet
14 Making Decisions in "C"
21 pages
loop
PDF
No ratings yet
loop
12 pages
2.2C Loop Control
PDF
No ratings yet
2.2C Loop Control
9 pages
Introduction To Looping Control Structures - 1
PDF
No ratings yet
Introduction To Looping Control Structures - 1
5 pages
Loop in C
PDF
No ratings yet
Loop in C
41 pages
Flowchart of While Loop in C
PDF
No ratings yet
Flowchart of While Loop in C
5 pages
EEE122_LabSheet4
PDF
No ratings yet
EEE122_LabSheet4
11 pages
Lab 4
PDF
No ratings yet
Lab 4
5 pages
Loops
PDF
No ratings yet
Loops
14 pages
While Loop Is Used When You Want To Execute A Block of Statements Repeatedly With Checked
PDF
No ratings yet
While Loop Is Used When You Want To Execute A Block of Statements Repeatedly With Checked
5 pages
C - Infinite Loop
PDF
No ratings yet
C - Infinite Loop
10 pages
Iterations - Loops in C Programming
PDF
No ratings yet
Iterations - Loops in C Programming
29 pages
Ch-5.2 Loop
PDF
No ratings yet
Ch-5.2 Loop
29 pages
Control or Iterative Structures
PDF
No ratings yet
Control or Iterative Structures
7 pages
Looping
PDF
No ratings yet
Looping
9 pages
Iterative Statement D
PDF
No ratings yet
Iterative Statement D
13 pages
Practical Slot 4
PDF
No ratings yet
Practical Slot 4
4 pages
While Loop in C Programming Language With Examples PDF
PDF
0% (1)
While Loop in C Programming Language With Examples PDF
3 pages
Inbound 58108971327046803
PDF
No ratings yet
Inbound 58108971327046803
20 pages
The Islamia College of Science & Commerce, Srinagar - J &K: (UGC-Autonomous)
PDF
No ratings yet
The Islamia College of Science & Commerce, Srinagar - J &K: (UGC-Autonomous)
13 pages
Loops in C
PDF
No ratings yet
Loops in C
13 pages
Chap - 3 Loops in C Language
PDF
No ratings yet
Chap - 3 Loops in C Language
28 pages
Unit 7 - Looping With While, Do-While and For
PDF
No ratings yet
Unit 7 - Looping With While, Do-While and For
8 pages
Introduction To Loops
PDF
No ratings yet
Introduction To Loops
24 pages
Labsheet 5
PDF
No ratings yet
Labsheet 5
15 pages
Chapter 3 Looping
PDF
No ratings yet
Chapter 3 Looping
20 pages
Loops
PDF
No ratings yet
Loops
4 pages
Week 3
PDF
No ratings yet
Week 3
10 pages
Part 2 - Conditional Branching and Loops
PDF
No ratings yet
Part 2 - Conditional Branching and Loops
18 pages
C Loops
PDF
No ratings yet
C Loops
9 pages
Lecture 2.1.1 Looping Statements
PDF
No ratings yet
Lecture 2.1.1 Looping Statements
22 pages
Chap 3 Looping
PDF
No ratings yet
Chap 3 Looping
13 pages
Chap 6
PDF
No ratings yet
Chap 6
32 pages
While Loop in C
PDF
No ratings yet
While Loop in C
6 pages
Unit3 Chapter1
PDF
No ratings yet
Unit3 Chapter1
18 pages
Looping Statements in C - 6 Looping Statements and Usage (For, While, Do... While
PDF
No ratings yet
Looping Statements in C - 6 Looping Statements and Usage (For, While, Do... While
8 pages
10-C - Loops
PDF
No ratings yet
10-C - Loops
6 pages
Structured Programming Language: The Loop
PDF
No ratings yet
Structured Programming Language: The Loop
53 pages
Do-While Loop in C
PDF
No ratings yet
Do-While Loop in C
6 pages
While Loop
PDF
No ratings yet
While Loop
4 pages
Tle Group 3
PDF
No ratings yet
Tle Group 3
25 pages
6_Loops in C
PDF
No ratings yet
6_Loops in C
33 pages
Loops Structure
PDF
No ratings yet
Loops Structure
26 pages
lec 6 pps
PDF
No ratings yet
lec 6 pps
10 pages
Control Statements (Looping) While-Do While and For
PDF
No ratings yet
Control Statements (Looping) While-Do While and For
27 pages