Control Flow  «Prev 


Overview of Java Statements

1) Assignment Statement in Java: The value of the variable is updated with the result of the expression.
1) Assignment Statement in Java: The value of the variable is updated with the result of the expression.

2) Method invocation statement: The print() method of the out object is invoked, passing the value of s as an argument.
2) Method invocation statement: The print() method of the out object is invoked, passing the value of s as an argument.

3) Declaration statement: The s variable is declared as being off the String type.
3) Declaration statement: The s variable is declared as being of the String type.

4) if-statement: The condition in an if statement must be a Boolean expression. The else clause may be omitted.
4) if-statement: The condition in an if statement must be a Boolean expression. The else clause may be omitted.

5) Switch statement: The switch value and the case values must evaluate to int values after numeric promotion.
5) Switch statement: The switch value and the case values must evaluate to int values after numeric promotion.

6) Switch statement (continued)- If a break statement is executed, execution continues after the switch statement.
6) Switch statement (continued)- If a break statement is executed, execution continues after the switch statement.

7)For statement: The code surrounded by the for statement is executed for values of i from 0 to the length of s minus 1.
7) For statement: The code surrounded by the for statement is executed for values of i from 0 to the length of s minus 1.

8) End of for statement: This is where the for statement ends.
8) End of for statement: This is where the for statement ends.

Modern Java
9) While statement: First, the condition is evaluated. If the condition is true, the nested statements are executed. If it is false, the statement after the while statement is executed. When the nested statements have executed, the condition is evaluated again.
9) While statement: First, the condition is evaluated. If the condition is true, the nested statements are executed. If it is false, the statement after the while statement is executed. When the nested statements have executed, the condition is evaluated again.

10) Do statement: The nested statements are executed. The condition is evaluated. If the condition is true, the nested statements are executed again. If the condition is false, the next statement after the do statement is executed.
10) Do statement: The nested statements are executed. The condition is evaluated. If the condition is true, the nested statements are executed again. If the condition is false, the next statement after the do statement is executed.

11) Break statements: Breaks without labels terminate execution of an enclosing switch, for, while, or do statement. Breaks with labels terminate execution of an enclosing statement with a matching label.
11) Break statements: Breaks without labels terminate execution of an enclosing switch, for, while, or do statement. Breaks with labels terminate execution of an enclosing statement with a matching label.

12) Continue statements: The continue statement terminates the current loop iteration (for, while, or do statement). A label may be used to identify the loop whose iteration is being terminated.
12) Continue statements: The continue statement terminates the current loop iteration (for, while, or do statement). A label may be used to identify the loop whose iteration is being terminated.

13) Return statement: Return statements return the value of an expression of the method's return value. If a method's return type is void, then the return statement does not return a value.
13) Return statement: Return statements return the value of an expression of the method's return value. If a method's return type is void, then the return statement does not return a value.

14) Throw statement: A throw statement throws an exception, which is an object of a subclass of java.lang.Throwable.
14) Throw statement: A throw statement throws an exception, which is an object of a subclass of java.lang.Throwable.

15) Try-catch statements: An exception that is thrown in the try clause may be caught and handled by a catch clause.
15) Try-catch statements: An exception that is thrown in the try clause may be caught and handled by a catch clause.

16) Synchronized statements: The lock on the object being synchronized must be acquired before the synchronized statement is executed.
16) Synchronized statements: The lock on the object being synchronized must be acquired before the synchronized statement is executed.