In this tutorial you will learn about the Java Control Flow Statements and its application with practical example.
Java Control Flow Statements
Control flow or flow of control is the order in which instructions, statements and function calls being executed or evaluated when a program is running. The control flow statements are also called as Flow Control Statements. In Java, statements inside your code are generally executed sequentially from top to bottom, in the order that they appear. It is not always the case your program statements to be executed straightforward one after another sequentially, you may require to execute or skip certain set of instructions based on condition, jump to another statements, or execute a set of statements repeatedly. In Java, control flow statements are used to alter, redirect, or to control the flow of program execution based on the application logic.
Java Control Flow Statement Types
In Java, Control flow statements are mainly categorized in following types –
Java Selection Statements
In Java, Selection statements allow you to control the flow of the program during run time on the basis of the outcome of an expression or state of a variable. Selection statements are also referred to as Decision making statements. Selection statements evaluates single or multiple test expressions which results in “TRUE” or “FALSE”. The outcome of the test expression/condition helps to determine which block of statement(s) to executed if the condition is “TRUE” or “FALSE” otherwise.
In Java, we have following selection statements –
Java Iteration Statements
In Java, Iteration statements are used to execute the block of code repeatedly for a specified number of times or until it meets a specified condition. Iteration statements are commonly known as loops or looping statements.
In Java, we have following iteration statements available-
Java Jump Statements
Jump statements are used to alter or transfer the control to other section or statements in your program from the current section.
In Java, we have following types of jump statements –
All of the above jump statements cause different types of jumps.