break
may be used with
for
,
while
,
do
-
while
loops
continue
exits the current loop and starts over at the first statement of the next loop
loop can have a name (name follow by colon)
break
LoopName
if
(
boolean
expression )
{
statements
}
else
if
{
statements
}
else
{
statements
}
switch
(
boolean
expression )
{
case
'A'
:
Statement(s);
Break
case
'B'
:
Statement(s);
Break
case
'C'
:
Statement(s);
Break
default
:
Statement(s)
}
Example
:
for
(
int
number
=
0 ; number
<
1000 ; number
++
)
{
if
(number
%
12
==
0) System.out.println(
"#: "
+
number) ;
// prints all numbers evenly divisible by 12
}
Example 2
:
for
( i
=
0 , j
=
0 ; i
*
j
<
1000 ; i
++
, j
+=
2)
{
//allowed to use more than one variable in the loop
System.outlprintln(i
+
" * "
+
j
+
" = "
+
i
*
j) ;
Example 3
:
for
( ; Count
<
MaxCount ; Count
++
)
// section of the loop can be missing
}