► |  | How to Design Classes Languages

1 | Professor J Beginner
2 | Professor J Intermediate
3 | Professor J Intermediate + Access
4 | Professor J Advanced
| Index

▼ | 4 | Professor J Advanced

4.1 | package
4.2 | import
4.3 | class
4.4 | interface
4.5 | Modifiers
4.6 | Field
4.7 | Method
4.8 | Constructor
4.9 | Statement
4.10 | Array Init
4.11 | Expression

Version: 4.1.4
top← prev up next →

#### 4.9`` Statement

- Expression = Expression ;

  The first expression must be a field reference, array position reference, or a variable. The value of this variable, field, or array position will be changed to be the value of the evalauated expression on the right-hand side of =.

- if (Expression) Statement else Statement

  In this statement the expression should have a boolean type. It is evaluated first. If the expression evaluates to true, then the first statement (known as the then clause) is evaluated. If the expression evaluates to false, the statement following else (the else clause) is evaluated. Both statements may be blocks, including { }.

- if (Expression) Statement

  In this statement the expression should have a boolean type. It is evaluated first. If the expression evaluates to true, then the statement is evaluated; otherwise the statement has completed evaluation.

- return Expression ;

  This form evaluates the expression, and then returns the value of the expression as the result of the method in which it is contained.

- return ;

  This form causes the method to cease evaluation, without producing a value. Should be used in conjunction with void for the MethodReturn.

- {Statement ...}

  This statement groups the sequence of statements together, commonly called a block. The statements evaluate sequentially.

- while (Expression) {Statement ...}

  Evaluates the expression, which must have type boolean. If the resulting value is true, then the statements are evaluated. After evaluating the statements, the expression is evaluated again. This repeats until the resulting value is false; once false, the statements are not evaluated and the while statement has completed evaluation.

- do {Statement ...} while (expression)

  The do statement evaluates the Statements, and then evaluates the expression, which must have type boolean. If the expression is true the statements evaluate again. This repeats until the expression is false, afterwhich the do statement has completed evaluation.

- for (ForInit ForExpression ForUpdate ,...) {Statement ...}

  The ForInit first initializes a variable, or evaluates a set of expressions. The variable can only be seen within the ForExpression, ForUpdate, and within the Statements. Then the ForExpression is evaluated, when true the Statements are evaluated. Subsequently, the ForUpdate evaluates a set of statement expressions or assignments before evaluating the expression again. Other than the ForInit stage, this repeats until the expression evaluates to false, afterwhich the for statement has completed evaluation.

- break ;

  Can only appear within the statement group of a while loop, do loop, or for loop. Causes the loop evaluation to complete without checking the expression again.

- continue ;

  Can only appear within the statement group of a while loop, do loop, or for loop. Causes the statement group evaluation to complete, repeating to the evaluation of the conditional.

- super (Expression ,...) ;

  May only appear as the first statement of a constructor. Calls the constructor for the parent class using the given expressions as arguments. Expressions are evaluated left to right.

- this (Expression ,...) ;

  May only appear as the first statement of a constructor. Calls a different constructor from the same class, chosen by analyzing the given expressions.

- Type Id ;

  Creates a local variable Id within a method body or a block statement; it is not visible outside the block or method, or to statements the preceed the declaration. The variable must be initialized prior to use.

- Type Id = Expression ;

  Creates a local variable Id within a method body or a block statement.

- StatementExpression ;

  This set of expressions can be used in a statement position, provided they are followed by ’;’.

top← prev up next →