Control Statement
Java supports two selection statements that are if and Switch. These statements permits you to control the flow of your program's execution based upon conditions knows just during run time. If your background in programming does not involve C/C++ you will be pleasantly surprised through the power and flexibility holds in these two statements.
The if statement is Java's conditional branch statement. Control statement can be used to route program execution by two different paths. Here is the common form of the if statement .
if (condition ) statement1;
else statment2;
In the syntax, each statement might be a single statement or a compound statement enclosed within curly braces (which is, a block). A condition is any expression the returns a Boolean value. Here the else clause is optional.
The if works such as this. If the condition is true then statment1 is executed. Or else, statement2 (if it exists) is executed. Within no case will both statements be executed. For instance, let consider the given example.
int a, b;
/ / ....
if(a < b) a= 0;
else b= 0;
Here if a is less than b, then a is set to zero. Or else, b is set to zero. With no case both set to zero.