0% found this document useful (0 votes)
69 views

Loops and Decision Making Statements in C Language

The document discusses different types of decision-making statements and loops in the C programming language. It describes the if statement, if-else statement, and provides examples of each. It also covers for, while, and do-while loops. The if statement and if-else statement execute code depending on whether a boolean expression is true or false. Loops allow code to repeat execution for a set number of times or as long as a condition remains true.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Loops and Decision Making Statements in C Language

The document discusses different types of decision-making statements and loops in the C programming language. It describes the if statement, if-else statement, and provides examples of each. It also covers for, while, and do-while loops. The if statement and if-else statement execute code depending on whether a boolean expression is true or false. Loops allow code to repeat execution for a set number of times or as long as a condition remains true.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Shahzaib Shahid M.

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:

C programming language provides the following types of decision-making statements.

 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:

a is less than 20;


&
value of a is : 10
Shahzaib Shahid M.sc Physics AIOU,ISB
 If-Else statement:
An if statement can be followed by an optional else statement, which executes when the
Boolean expression is false.
The syntax of an if...else statement in C programming language is:

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

You might also like