5 Lecture-If Statment
5 Lecture-If Statment
Algorithms
is called an algorithm.
Specifying the order in which statements are to be executed in a computer program is called
program control.
Pseudocode & Flowcharts
Control structures
sequence structure
selection structure
repetition structure
while
do…while
for
Sequence
Three types of selection
Three types of repetition.
true
grade >= 60 print “passed”
false
The if…else selection statement
The pseudocode statement:
If student’s grade is greater than or equal to 60
Print “Passed”
else
Print “Failed”
The preceding pseudocode If…else statement may be written in C as
if ( grade >= 60)
cout<<passed;
else
cout<<Failed;
Flowcharting the double-selection if…else statement:
* The third operand is the value for the entire conditional expression
if the condition is false.
*Notice the braces surrounding the two statements in the else statement.
*These braces are important.
*Without the braces, the statement
would be outside the body of the else part of the if, and would execute
regardless of whether the grade is less than 60.