0
How to use continue
You'll find my code down my question is why when I run it it says continue is not properly in a loop why what's the problem and I honestly don't understand the usage of continue I mean where to put it in the code i=[1,7,9,0,8,] if i==9: print(i) continue
2 Antworten
+ 3
continue is usually used in a loop as far as I know , maybe that's y u r getting am error.
What continue does is it ignores everything after continue , simply saying it fast forwards to next iteration of the loop. Example :-
i = 0
while i<5:
if i%2==0:
print("Even")
continue
print("Odd")
The Output will be Even,Odd,Even,Odd, Even.
+ 1
Continue is used to jump to the next iteration in a loop (a block of code that gets executed multiple times). An if statement runs the code inside it only once (if the condition is true), so it is not a loop. Continue can only be used in and only makes sense in the context of a loop.
After the condition of an if statement is evaluated, if it is true it runs the code block inside it and then continues on to the next part of the code. If it is false, it just continues to the next part of the code, so there would be no need for a "continue" anyway.
As for your code itself, you have defined "i" as a list, then your condition in the if statement compares it to an integer. Lists and integers are not the same type! Do you mean to run through the list and then if the list item is "9", print it? If so, you need to use a for loop for that purpose.