+ 1
What's the difference between (else ) and (continue) in python ??!!
When can I use else with if and when we use continue ??...... which the best way between them? ???!
6 Respuestas
+ 1
If you play it through in your mind, you see that the same thing happens, but for different reasons.
In the second variation, what happens is obvious.
In the first variation you get the even-part when the if is true (just like in the other example), then continue forces the next number.
If the condition is not true, the code moves on to the print statement.
It is regularly the case that you can do the same job in several ways. Then you have to choose, for example what's best readable or most efficient for the computer.
+ 2
Thanks Armaan ... I know that's they work with conditions ....
But look at this code they are giving the same result
#if with continue
#=================
for number in range(0,101):
if number%2==0:
print("even number is:", number)
continue
print("number is not even", number)
#if with else
#=============
for number in range(0,101):
if number%2==0:
print("even number is:", number)
else:
print("number is not even", number)
+ 1
Thanks Theophile
Yor answer is right but in java language
I find different result with python look at above code and run it you will find different result your opinion.
0
It depends on conditions simply
0
Here is an example :
i = 0
while i < 10:
if i == 5:
continue
else:
print(i)
i += 1
#outputs 012346789
0
Are the same but the difference in the language of Java does not apply to continue the condition