Professional Documents
Culture Documents
Lab Midterm Exam
Lab Midterm Exam
Contents
C Loops: For, While, Do While, Looping Statements with Syntax & Example .............................................. 3
1. What is Loop in C?............................................................................................................................. 3
➢ Types of Loops in C........................................................................................................................ 3
2. While Loop in C ................................................................................................................................. 4
Syntax of While Loop in C: ................................................................................................................ 4
3. C for loop:.......................................................................................................................................... 5
Syntax of for loop: ................................................................................................................................. 5
Flow Diagram of for loop ................................................................................................................... 6
TASK 4: CREATE A TABLE IN MS WORD......................................................................................................... 6
Figure 1: Sample Loop ........................................................................................................................4
Figure 2: while loop flow chart ...........................................................................................................5
Figure 3: Flow diagram for loop ..........................................................................................................6
C Loops: For, While, Do While, Looping Statements with Syntax & Example
1. What is Loop in C?
Looping Statements in C execute the sequence of statements many times until the stated
condition becomes false. A loop in C consists of two parts, a body of a loop and a control
statement. The control statement is a combination of some conditions that direct the body of the
loop to execute until the specified condition becomes false. The purpose of the C loop is to
repeat the same code a number of times.
• What is Loop in C?
• Types of Loops in C
• While Loop in C
• Do-While loop in C
• For loop in C
• Break Statement in C
• Continue Statement in C
• Which loop to Select?
➢ Types of Loops in C
In an entry control loop in C, a condition is checked before executing the body of a loop. It is
also called as a pre-checking loop.
In an exit controlled loop, a condition is checked after executing the body of a loop. It is also
called as a post-checking loop.
Figure 1: Sample Loop
The control conditions must be well defined and specified otherwise the loop will execute an
infinite number of times. The loop that does not stop executing and processes the statements
number of times is called as an infinite loop. An infinite loop is also called as an "Endless
loop." Following are some characteristics of an infinite loop:
The specified condition determines whether to execute the loop body or not.
2. While Loop in C
A while loop is the most straightforward looping structure. While loop syntax in C programming
language is as follows:
while (condition) {
statements;
}
Flow chart for while loop
3. C for loop:
A1 A2 A3 C1 D1
B1
A4 A5 A6 D2 D3
A7 A8 A9 B2 C2
D4 E1
A10 C3
F1
𝑥⁄ + 5√𝑥& + ∫𝑛 ∑𝑚 𝑥 2
𝑦 𝑥−1 𝑦=1 𝑦