Software Development I : Software Development I Selection Statements
Objectives : Software Development I 2 Objectives After this topic you should be able to:
Implement selection control in a program using if statements.
Implement selection control in a program using switch statements.
Write boolean expressions using relational and boolean operators.
Evaluate given boolean expressions correctly.
Nest an if statement inside another if statement’s then or else part correctly.
The if Statement : Software Development I 3 The if Statement
Syntax for the if Statement : Software Development I 4 Syntax for the if Statement if ( )
else
Control Flow : Software Development I 5 Control Flow
Relational Operators : Software Development I 6 Relational Operators < //less than
<= //less than or equal to
== //equal to
!= //not equal to
> //greater than
>= //greater than or equal to
Compound Statements : Software Development I 7 Compound Statements Use braces if the or block has multiple statements. Then Block Else Block
The if-then Statement : Software Development I 8 The if-then Statement if ( testScore >= 95 )
mBox.show("You are an honor student"); if ( )
Control Flow of if-then : Software Development I 9 Control Flow of if-then
Boolean Expressions and Variables : Software Development I 10 Boolean Expressions and Variables
The Nested-if Statement : Software Development I 11 The Nested-if Statement The then and else block of an if statement can contain any valid statements, including other if statements. An if statement containing another if statement is called a nested-if statement.
Control Flow of Nested-if Statement : Software Development I 12 Control Flow of Nested-if Statement
if – else if Control : Software Development I 13 if – else if Control
Syntax for the switch Statement : Software Development I 14 Syntax for the switch Statement switch ( ) {
:
…
:
}
Switch with no break Statements : Software Development I 15 Switch with no break Statements
Switch with break Statements : Software Development I 16 Switch with break Statements
Switch with the default Block : Software Development I 17 Switch with the default Block
Summary : Software Development I 18 Summary You should now know how to:
implement selection control in a program using if statements.
implement selection control in a program using switch statements.
write Boolean expressions using relational and Boolean operators.
evaluate given Boolean expressions correctly.
nest an if statement inside another if statement’s then or else part correctly.