Hello friends, lets learn about the if-elif-else structure.
In C we write else if, here we use elif.
else is optional.
Check out this program:
In C we write else if, here we use elif.
else is optional.
Check out this program:
x = 5
y = 10
z = 20
if x > y:
print ('x is greater than y')
elif x < z:
print ('x is less than z')
elif 5>2:
print ('5 is greater than 2')
else:
print ('if and elif(s) never ran')
Output |
The if elif else is a code together, anyone one of it returns true then we come out of the loop.
As in this case, we see than 5>2 is true but since the statement above it is true, it came out of the loop.