if Statements | SoloLearn: Learn to code for FREE!

+1

if Statements

Hello, In an If Statement, if the first condition is not true, so all other conditions that follow it are not. Isn't it?

7/7/2019 12:18:22 PM

KHADIJA AI

4 Answers

New Answer

+2

for instance: sub=6 if sub<5: (1) print("smaller than 5") if sub>3: (2) print("bigger than 3") in here, since the first condition isn't verified, the second one won't be checked.

+2

just a doubt.. thanks for taking it off.

+1

KHADIJA AI Your question is not very clear. If the following explanation is not what you are looking for, then please provide the example for which you have a doubt. x = 5 y = 10 if x > 5 || y < 10: (1) doSomething() if x > 5 && y < 10: (2) doSomething() In (1) if the condition x > 5 fails, then the compiler will check if y < 10, if this is true then function doSomething() will be called. If first condition is true, the second condirion will be not be checked and doSomething function is called. In (2) if the first condition x>5 fails no further condition will be checked, the whole if block will be skipped. If however first condition pass, then second condition will be checked and only if that is true function doSomething will be executed. (1) is called logical OR condition and (2) is called logical AND

+1

KHADIJA AI Yes it will not be checked since second if is inside first if. When the first if fails, the code never enters the if block