In: Computer Science
By using examples differentiate between a single‐alternative and a dual‐ alternative if statement. 8 marks
Single Alternative If statement :- This is the simplest version of if statement.Single alternative if statement is the statement in which it provides only one alternative path of execution. If condition is true, some process is executed, but if condition is not true,exit the structure.
For example:- If(I having fishing pole) then I am going to
fishing.
Note:- In the above example, it tells you what to do if the
condition is true, but on the other hand it does not tells you what
to do if the condition is false.
Flow chart of Single Alternative If Statement:-
Dual Alternative If statement :- Dual alternative If statement is also known as IF then ELSE. Dual alternative if statement provides two alternative path of execution i.e. there is an action (statement to be executed) on the true branch as well as on the false branch. Hence, if the if-condition is false, there is alternative statement to execute i.e. Else Statement which was not the case in the single alternative if statement.
For example :- If (x>10) then print "Greater than 10" else
print "smaller".
Note :- Here it tells you what to do if the condition is true as
well as if the condition is false.
Flow chart of Dual
Alternative If Statement :-