Vous êtes sur la page 1sur 9

Selection Statement

Simple if statement
if(boolean){
statements
}
If..else statement
if(boolean){
statements
}else{
statements
}

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 1


Selection Statement
Nested if statement
if(boolean){
if(boolean){
statements
}
}else if(boolean){
statements
}else{
statements
}

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 2


Selection Statement
A switch works with the byte, short, char, and
int primitive data types.
It also works with enumerated types, the String class,
and a few special classes that wrap certain primitive
types:
Character, Byte, Short, and Integer.
switch (month) {
case 1: statement
break;
case 2: statement
break;
default: statement
break;
}
CT038-3.5-2 Object Oriented Development with Java Programming Concepts 3
Loop Statement
while loop
while(loop-continuation-condition){
//loop body
}

do-while loop
do{
//loop body
}while(loop-continuation-condition);

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 4


Loop Statement
for loop

for(initial-action; loop-continuation-condition;
action-after-each-iteration){
//loop body
}

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 5


Loop Statement
Enhanced-for
The enhanced for-loop is a popular feature
introduced with the Java SE platform in
version 5.0.
Its simple structure allows one to simplify
code by presenting for-loops that visit each
element of an array/collection without
explicitly expressing how one goes from
element to element.

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 6


Loop Statement
Enhanced-for
for (int i=0; i < array.length; i++) {
System.out.println("Element: " + array[i]);
}

to the newer form,

for (String element : array) {


System.out.println("Element: " + element);
}

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 7


Summary
We discussed the module covering the following:
data types and object type
primitive data types and wrapper classes
standard operators
if, if-else, else-if and nested if and switch
while, do-while, for, enhanced-for

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 8


Q&A

CT038-3.5-2 Object Oriented Development with Java Programming Concepts 9

Vous aimerez peut-être aussi