Mini Final ppt-1
Mini Final ppt-1
Theory:
In programming, loops are used to repeat a block of code until a specified condition is met. C
programming has three types of loops.
while loop
for loop
do-while loop
1. While Statement
Syntax:
while (testExpression )
{
//Statements to be executed repeatedly
// Increment (++) or Decrement (--) Operation
}
The while loop evaluates the testExpression inside the parentheses ().
If testExpression is true, statements inside the body of while loop are executed. Then,
testExpression is evaluated again.
The process goes on until testExpression is evaluated to false.
If testExpression is false, the loop terminates (ends).
2. do-while Statement
3. For statement
The for loop operation is controlled by the contents of the parentheses that follow the
keyword for
13
Lab Manual: Programming for Problem Solving
}
Working:
• The initialization statement is executed only once.
• Then, the test expression is evaluated. If the test expression is evaluated to false,
the for loop is terminated.
• However, if the test expression is evaluated to true, statements inside the body of
the for loop are executed, and the update expression is updated.
• Again the test expression is evaluated.
• This process goes on until the test expression is false. When the test expression is
false, the loop terminates.
14