CS212 - Object Oriented Programming-Week1-3
CS212 - Object Oriented Programming-Week1-3
Oriented
Programming
Control Sturctures
in Java
Mehwish Kiran
[email protected]
Agenda
• Algorithms
• Program Flow Control
• Selection Structures
• Repetition Structures
Algorithms
If statements
If-else statements
Nested if-else statements
Switch case statements
Detect the output
Detect the output
Switch Statements
• The switch differs from the if in that switch can only test
for equality, whereas if can evaluate any type of Boolean
expression.
• No two case constants in the same switch can have
identical values.
• A switch statement is usually more efficient than a set of
nested ifs.
Challenge
While Loop
Do-while Loop
For Loop
For each Loop (will be discussed later with Arrays)
Types of Control
“Beat the mixture
Conditions 300 strokes,”
“Cut with a pastry
blender until the
Count
mixture resembles er A loop that executes a
coarse meal,” Contro specified number of times
lled
A loop that terminates
when something happens Event
inside the loop body to
signal that the loop should Controlled
be exited.
The Do-while Loop
• The Do-While statement is
a looping control structure
in which the loop condition
is tested at the end
(bottom) of the loop. This
format guarantees that the
loop body executes at
least once
For Loop
Using the Comma
For Loop Variations
Detect the output
Thank you
Consultation Hours
Thursday 10:00 to
11:00am
Please email to book your
slot