0% found this document useful (0 votes)
5 views23 pages

CS212 - Object Oriented Programming-Week1-3

The document outlines key concepts in object-oriented programming with a focus on control structures in Java, including algorithms, program flow control, selection structures, and repetition structures. It details various control structures such as if statements, switch statements, and different types of loops. Additionally, it includes a programming challenge and consultation information for further assistance.

Uploaded by

mehwish.kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views23 pages

CS212 - Object Oriented Programming-Week1-3

The document outlines key concepts in object-oriented programming with a focus on control structures in Java, including algorithms, program flow control, selection structures, and repetition structures. It details various control structures such as if statements, switch statements, and different types of loops. Additionally, it includes a programming challenge and consultation information for further assistance.

Uploaded by

mehwish.kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

CS212 - Object

Oriented
Programming
Control Sturctures
in Java
Mehwish Kiran
[email protected]
Agenda

• Algorithms
• Program Flow Control
• Selection Structures
• Repetition Structures
Algorithms

A procedure for solving a problem in terms of


1. the actions to execute and
2. the order in which these actions execute
is called an algorithm.
Program Control

Specifying the order in which statements (actions)


execute in a program is called program control.
There are three types of control structures is Java
• Sequence structure
• Selection structure
• Repetition structure
Selection Structure

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

Write a program which takes string input for city


name in pakistan from user and prints the area
code of that city by using switch statement.
(you can choose any 5 cities )
Detect the output
Detect the output
Repetition Structure

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

You might also like