Professional Documents
Culture Documents
12
(MS Access and C)
Copyright © IT Series
Sequence
Executes the statements in the same order in which they are written in the program
Flowchart
Entry point
Exit point
if-else
if-else-if
switch
Exit point
Exit point
statement;
The syntax for compound statements:
if (condition)
{ Block of statements
statement 1; inside the braces is
called the body of the if
statement 2; statement. If there is
only 1 statement in the
body, the { } may be
statement N; omitted.
}
Copyright
Copyright @©ITITSeries
Series www.itseries.com.pk
The simplest selection structure but it is very limited in its use
Statement or set of statements is executed if the condition is true
But if the condition is false then nothing happens (no alternate action is performed)
A user may want to:
Execute one statement or set of statements if the condition is true
possible to perform mathematical operation on character values
Execute other statement or set of statements if the condition is false
In this situation, simple if statement cannot be used effectively
Solution ‘if-else’ structure can be used to handle this kind of situation effectively
Example
A program should display Pass! if the student gets 40 or more marks
It should display Fail! if the student gets less than 40 marks
Simple if statement cannot be used to handle this situation
Condition
Statement
Copyright © IT Series
If-else Programs
Copyright
Copyright @©ITITSeries
Series www.itseries.com.pk
possible to perform mathematical operation on character values
Copyright
Copyright @©ITITSeries
Series www.itseries.com.pk
It is used when there are many options and only one block of statements should be executed on the basis of
a condition
Working of if-else-if
The condition 1 is evaluated and the first block of statements is executed if the condition 1 is true
The condition 2 is evaluated if the condition 1 is false. The second block of statements is executed if the
condition 2 is true
The block of statements after the last else is executed if all conditions are false
Copyright © IT Series
if-else-if Programs
Copyright
Copyright @©ITITSeries
Series www.itseries.com.pk
possible to perform mathematical operation on character values
Copyright © IT Series
possible to perform mathematical operation on character values
Copyright © IT Series
possible to perform mathematical operation on character values
Working of Nested if
the condition of outer if is evaluated first. If it is true, the control enters the inner if block
If the condition is false, the inner if is skipped and control directly moves to the else part of outer if
If outer if is true, the control enters the inner if statement
The inner if evaluated according to simple if statement
Copyright © IT Series
Nested if Programs
Copyright
Copyright @©ITITSeries
Series www.itseries.com.pk
possible to perform mathematical operation on character values
Copyright
Copyright @©ITITSeries
Series www.itseries.com.pk