|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Use thewhilestatement 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-whilestatement 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
forstatement 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 basicifstatement whose single statement block is executed if the boolean expression is true.Anif (boolean expression) { statements }ifstatement 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 }ifstatement with multiple expressions.Anif (boolean expression) { statements } else if (boolean expression) { statements }ifstatement with multiple expressions and anelsestatement.Theif (boolean expression) { statements } else if (boolean expression) { statements } else { statements }switchstatement evaluates and integer expression and executes the appropriatecasestatement.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, andfinallystatements to handle exceptions.try { statements } catch (exceptiontype name) { statements } catch (exceptiontype name) { statements } finally { statements }
Use the unlabelled form of thebreakstatement to terminate the innermostswitch,for,while, ordostatement.Use the labelled form of thebreak;breakstatement to terminate an outerswitch,for,while, ordostatement with the given label:Abreak label;continuestatement terminates the current iteration of the innermost loop and evaluates the boolean expression that controls the loop.The labelled form of thecontinue;continuestatement terminates the current iteration of the loop with the given label and evaluates the boolean expression that controls the loop.Usecontinue label;returnto terminate the current method.You can return a value to the method's caller, by using the form ofreturn;returnthat takes a value.return value;
|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |