📝 Bank exam prep made easy — free interactive practice on Leyaa.ai →


if else statement

Statements under 'if' executes only when the given condition is true.

Otherwise, the statements under 'else' will be executed.


When we need to decide either this or that in programming, we should go for if-else statement.

Like,

positive or negative

prime or composite

odd or even etc.




Syntax

Example

if condition:
  #statements
else:
  #statements

Pictorial Explanation

if else statement in c




Sample Program

Get a number from user and say whether it is zero or non-zero number.

Example

num = int(input("Enter a number"))

if num == 0:
  print("Zero")
else:
  print("Non Zero")


Topics You Might Like


📝 Preparing for SBI PO, IBPS, or placement aptitude?

Free interactive practice for Quantitative Aptitude, Reasoning Ability & Banking Awareness — available in English, Hindi & Tamil.

Start Practicing on Leyaa.ai →