+ 3

How do you end an else statement?

How do you end an else statement?

1st Sep 2021, 6:27 PM
Hack
Hack - avatar
4 Answers
+ 13
if... else is done like this: some code before the if... else... block ... if some_condition: do this1 do this2 ... else: do this3 .... do this4 # this is outside the if.. else... block so the if... else... ends in this sample when codelines have the same indentation level as before starting the if ... else ... block.
1st Sep 2021, 6:43 PM
Lothar
Lothar - avatar
+ 3
Thank you both
2nd Sep 2021, 9:10 AM
Hack
Hack - avatar
+ 1
If blah blah blah == blah blah blah :*the condition. I am iron man *the work to be done if the the condition is true/satisfied else: *not true(else ends with a :) I am not iron man*work done when condition is not true/satisfied.
3rd Sep 2021, 5:58 AM
LONMemer
LONMemer - avatar
0
Sometimes the for or while loop can ends else. It do like if else. If there is break in the body of the loop, then else will not be executed.
2nd Sep 2021, 3:08 PM
Iritaka
Iritaka - avatar