Loops and Decision Making Statements in C Language
Loops and Decision Making Statements in C Language
sc Physics AIOU,ISB
Decision Making In C Language:
Decision-making structures require that the programmer specifies one or more conditions to be
evaluated or tested by the program, along with a statement or statements to be executed if the
condition is determined to be true, and optionally, other statements to be executed if the
condition is determined to be false. Shown below is the general form of a typical decision-
making structure found in most of the programming languages:
If Statement:
Shahzaib Shahid M.sc Physics AIOU,ISB
An if statement consists of a Boolean expression followed by one or more statements. The
syntax of an ‘if’ statement in C programming language is:
If the Boolean expression evaluates to true, then the block of code inside the ‘if’ statement will be
executed. If the Boolean expression evaluates to false, then the first set of code after the end of the ‘if’
statement (after the closing curly brace) will be executed.
Flow Diagram:
Example:
Shahzaib Shahid M.sc Physics AIOU,ISB
When the above code is compiled and executed, it produces the following result:
Flow Diagram:
Shahzaib Shahid M.sc Physics AIOU,ISB
Shahzaib Shahid M.sc Physics AIOU,ISB
Loops in C-Language:
A loop statement allows us to execute a statement or group of statements multiple times. Given
below is the general form of a loop statement in most of the programming languages:
Shahzaib Shahid M.sc Physics AIOU,ISB
Shahzaib Shahid M.sc Physics AIOU,ISB
Shahzaib Shahid M.sc Physics AIOU,ISB
Shahzaib Shahid M.sc Physics AIOU,ISB
Example:
++
Shahzaib Shahid M.sc Physics AIOU,ISB
Do – While Loop:
Notice that the conditional expression appears at the end of the loop, so the statement(s) in the
loop executes once before the condition is tested. If the condition is true, the flow of control jumps
back up to do, and the statement(s) in the loop executes again. This process repeats until the given
condition becomes false.
Shahzaib Shahid M.sc Physics AIOU,ISB
a = a++
}
Shahzaib Shahid M.sc Physics AIOU,ISB