0% found this document useful (0 votes)
18 views

Chapter Three

This document discusses decision and repetition statements in Java programming. It covers if/else statements, switch case statements, and different types of loops including while, do while, and for loops. If/else statements allow a program to make decisions based on conditions, and can be one-way, two-way, nested, or multi-way. Switch statements execute code based on the value of a variable. Loops allow code to repeat, with while and do-while checking conditions differently from for loops.

Uploaded by

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

Chapter Three

This document discusses decision and repetition statements in Java programming. It covers if/else statements, switch case statements, and different types of loops including while, do while, and for loops. If/else statements allow a program to make decisions based on conditions, and can be one-way, two-way, nested, or multi-way. Switch statements execute code based on the value of a variable. Loops allow code to repeat, with while and do-while checking conditions differently from for loops.

Uploaded by

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

CHAPTER THREE

DECISION AND REPETITION


STATEMENTS
2

Outline
• If/else statement
• Switch case
• While loop
• Do while loop
• For loop
3

Decision statements
• The program can decide which statements to execute based on a condition.

• Java has several types of selection statements:

• one-way if statements

• two-way if-else statements

• nested if statements

• multi-way if-else statements

• switch case statements, and

• conditional expressions.
4

Decision statm…
one way if statement
•A one-way if statement executes an action if and only if the condition is
true.
Syntax

•If the boolean-expression evaluates to true, the statements in the


block are executed. As an example, see the following code:
5

Decision statm…
• The block braces can be omitted if they enclose a single statement. For

example, the following statements are equivalent.

• Two-Way if-else Statements

• An if-else statement decides the execution path based on whether the

condition is true or false.


• Syntax


6

Dec statem…
Example.

• Nested if and Multi-Way if-else Statements


• An if statement can be inside another if statement to form a nested if
statement.
• Example
7

Dec statmn…
• Example multi way if statement

Switch Statements
• A switch statement executes statements based on the value of a variable or
an expression.
8

Dec statem…

• Repetition (loop) statements


• A loop can be used to tell a program to execute statements repeatedly.
• Three types of loops in java: while, do while and for loop.
9

Loops in java
while Loop
•A while loop executes statements repeatedly while the condition is
true.

•Do while loop


•A do-while loop is the same as a while loop except that it executes the
loop body first and then checks the loop continuation condition.
Comparative Study of Programming Languages Joey Paquet, 2010-2014 10

End of chapter two

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy