0
Why didnt the code stop running?
num = 12 if num > 5: print("Bigger than 5") if num >=47: print("123456")*should the code not have stopped here and ignored the next part? if num <=47: print("Between 5 lol")
3 Antworten
+ 1
Conditional statements and loops are different.
This being a conditional statement, if a given condition is false then it is simply ignored. So the program will not terminate.
Since if num <= 47 is still inside the outer if statement, it will execute because the condition returns true.
0
I think I got it now, thanks guys!
#NOTES on control structures and "if" statements.
num = 12
if num > 5:
print("bigger than 5")
if num >= 47:
print("lol") #will stop running here due to the code being "False" and the next statement being "nested"
if num == 12:
print("hioh")
#however if we do the same thing again, only this time releasing the nest, the second condition is ran as normal.
num = 12
if num > 5:
print("bigger than 5")
if num >= 47:
print("lol") #we will release this now
if num == 12:
print("hioh")#which now will print "hioh"
0
if one "if" statement is false doesn't means program stops ,the another "if" and other if's will be checked as well given they all have same indentation level like in your case