09.3 Control Flow
Java provides six language constructs to transfer control or exit loops in a program.
- break
- continue
- return
- try …catch …finally
- throw
- assert
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 statements are executed. In case it is false, the Java Virtual Machine (JVM) throws a special error of AssertionError class. Assertion errors are not handled 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.
2 thoughts on “09.3 Control Flow”
Comments are closed.
Great blog. I would like to appreciate you.Keep going like this.
Best Selenium Training Institute In Hyderabad | Online Selenium Training
Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as
appvn