What's the difference between (else ) and (continue) in python ??!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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? ???!

10th Mar 2019, 8:36 PM
Abdulmalek Mohammed Jayash
Abdulmalek Mohammed Jayash - avatar
6 Answers
+ 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.
10th Mar 2019, 9:42 PM
HonFu
HonFu - avatar
+ 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)
10th Mar 2019, 9:37 PM
Abdulmalek Mohammed Jayash
Abdulmalek Mohammed Jayash - avatar
+ 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.
10th Mar 2019, 9:42 PM
Abdulmalek Mohammed Jayash
Abdulmalek Mohammed Jayash - avatar
0
It depends on conditions simply
10th Mar 2019, 8:47 PM
Tahir Iqbal
Tahir Iqbal - avatar
0
Here is an example : i = 0 while i < 10: if i == 5: continue else: print(i) i += 1 #outputs 012346789
10th Mar 2019, 9:18 PM
Théophile
Théophile - avatar
0
Are the same but the difference in the language of Java does not apply to continue the condition
11th Mar 2019, 5:12 AM
Amani Ahmed
Amani Ahmed - avatar