JAVA Statements

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

JAVA Statements

if else Statement
if else Statement
if else Statement

An if-then-else statement can test:


 expressions based on ranges of values
 conditions
if else Statement

The example in the slide demonstrates the syntax for an if-else


statement in Java.
The else statement provides a secondary path of execution when
an if clause evaluates to
false.
The output from the code in the slide is False.
Switch-case Statement

switch()
case:

default:
Switch-case Statement

A switch statement tests expressions based only on a:


 single integer
 Character
 enumerated value
 String object
Switch-case Statement
Switch-case Statement

A switch statement is used to compare the value of a variable with multiple values. For each of
these values, you can define a set of statements to execute. The switch statement evaluates its
expression, then executes all statements that follow the matching case label. Each break
statement terminates the enclosing switch statement. The break statements are necessary
because without them, statements in switch blocks fall through: All statements after the
matching case label are executed in sequence, regardless of the expression of subsequent case
labels, until a break statement is encountered.

You might also like