![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Use thewhile
statement to loop over a block of statements while a boolean expression remains true. The expression is evaluated at the top of the loop.while (boolean expression) { statements }Use the
do
-while
statement to loop over a block of statements while a boolean expression remains true. The expression is evaluated at the bottom of the loop.do { statement } while (expression);The
for
statement loops over a block of statements and includes an initialization statement, a termination condition statement, and an increment statement.for (initialization ; termination ; increment) { statements }
A basicif
statement whose single statement block is executed if the boolean expression is true.Anif (boolean expression) { statements }if
statement with one boolean expression and two statement blocks. The first statement block is executed if the boolean expression is true and the second is executed if the boolean expression is false.Anif (boolean expression) { statements } else { statements }if
statement with multiple expressions.Anif (boolean expression) { statements } else if (boolean expression) { statements }if
statement with multiple expressions and anelse
statement.Theif (boolean expression) { statements } else if (boolean expression) { statements } else { statements }switch
statement evaluates and integer expression and executes the appropriatecase
statement.switch (integer expression) { case integer expression: statements break; ... default: statements break; }
Throw an exception to indicate that an error occurred.Use thethrow exception;try
,catch
, andfinally
statements to handle exceptions.try { statements } catch (exceptiontype name) { statements } catch (exceptiontype name) { statements } finally { statements }
Use the unlabelled form of thebreak
statement to terminate the innermostswitch
,for
,while
, ordo
statement.Use the labelled form of thebreak;break
statement to terminate an outerswitch
,for
,while
, ordo
statement with the given label:Abreak label;continue
statement terminates the current iteration of the innermost loop and evaluates the boolean expression that controls the loop.The labelled form of thecontinue;continue
statement terminates the current iteration of the loop with the given label and evaluates the boolean expression that controls the loop.Usecontinue label;return
to terminate the current method.You can return a value to the method's caller, by using the form ofreturn;return
that takes a value.return value;
![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |