9.3 | Transfer Statement
Java provides six language constructs to tranfer control or exit loops in a program.
continue ...statement
continue ...statement exits the current iteration and starts executing the next iteration.
For example, the following code prints all numbers except number 3.
return ...statement
return ...statement stops code execution of a method and transfer control back to the calling code.
try ...catch ...finally ...statement
try ...catch ...finally ...statement is used for handling exceptions. (Further, discuss in section 'Exception Handling'.)
throws ...statement
throws ...statement is used for handling exceptions. (Further, discuss in section 'Exception Handling'.)
assert ...statement
assert ...statements are used to validate the assumptions made about the program. Assertions are expected to be true when assert statement are executed. In case it is false, the Java Virtual Machine (JVM) throws a special error of AssertionError class. Assertion error are not handle but allowed to propagate to the top level.
Note: Assertion facility can be enabled or disabled at run-time. If disabled, assert statements are not executed during run-time.
Java provides six language constructs to tranfer control or exit loops in a program.
- break
- continue
- return
- try ...catch ...finally
- throw
- assert
break ...statement
break ...statement terminates a loop.
For example, the following code showed how to terminate a while and for a loop.
continue ...statement
continue ...statement exits the current iteration and starts executing the next iteration.
For example, the following code prints all numbers except number 3.
return ...statement
return ...statement stops code execution of a method and transfer control back to the calling code.
try ...catch ...finally ...statement
try ...catch ...finally ...statement is used for handling exceptions. (Further, discuss in section 'Exception Handling'.)
throws ...statement
throws ...statement is used for handling exceptions. (Further, discuss in section 'Exception Handling'.)
assert ...statement
assert ...statements are used to validate the assumptions made about the program. Assertions are expected to be true when assert statement are executed. In case it is false, the Java Virtual Machine (JVM) throws a special error of AssertionError class. Assertion error are not handle but allowed to propagate to the top level.
Note: Assertion facility can be enabled or disabled at run-time. If disabled, assert statements are not executed during run-time.
1 comment:
Great blog. I would like to appreciate you.Keep going like this.
Best Selenium Training Institute In Hyderabad | Online Selenium Training
Post a Comment