Question:

What is branching statement, explain any one branching statement with suitable example?

Show Hint

Use branching statements like `if`, `else`, and `elif` to make decisions based on conditions in your program.
Updated On: Jan 9, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understanding Branching Statements.
A branching statement in programming is used to execute certain parts of code based on a condition. It allows a program to make decisions and choose different paths of execution. The most common branching statements are `if`, `else`, and `else if`.
Step 2: Explanation of `if` statement.
The `if` statement is the simplest form of branching, where a condition is checked, and if it is true, the code inside the `if` block is executed. Otherwise, the program moves on to the next statement.
Example of `if` statement:
Consider the following Python example:
age = 18
if age >= 18:
    print("You are eligible to vote.")
In this example, if the condition `age >= 18` is true, the program prints "You are eligible to vote". If the condition were false, the code inside the `if` block would be skipped.
Step 3: Conclusion.
Branching statements allow the program to make decisions and execute different parts of code depending on the conditions.
Was this answer helpful?
0
0