What is Branching?
Branching refers to the process of following one of two or more alternative paths of computation. This happens at a point where a test is performed to identify the conditions of certain variables in the process. The basis for selection of a particular path is stated within the decision box. The decision can be based on a comparison, on the value of a variable, on the sign of a variable, etc.
A few steps are by passed and the program is rejoined at a later stage, This is known as forward jump.
BRANCHING – THE IF….THEN STATEMENT
The IF….THEN is a decision making statement and, depending upon the decision, it can change the order of execution of statements. It is always used in conjunction with a relational expression.
It allows the computer to check whether a specified relation is TRUE or FALSE and to perform the transfer of control to a particular statement if it is TRUE.
This point of the program has two branches to follow, one for FALSE condition and the other for TRUE condition.
The syntax of ‘IF…THEN’ statement is as follows :
IF <relational expression> THEN
When an IF….THEN statement is encountered, the computer first evaluates the relational expression and then determines whether it is TRUE or FALSE.
If Condition is TRUE then all the statement which we can see between IF and ELSE are executed Otherwise, All the statement which we can see between ELSE and END IF are executed.
The flowchart of ‘IF….THEN’ statement is as below:
Example of ‘IF….THEN’ statement is as below :
Program to find maximum number of Two number.
PRINT “ENTER TWO NUMBER:”
INPUT A, B
IF A > B THEN
PRINT “ A IS LARGEST ”
PRINT “ B IS LARGEST ”