0
Why the command is not executed.
Help for a beginner. Question on the exercise.
3 Answers
+ 2
When continue statement is executed, the program will go back to the innermost loop's expression line.
In the example the innermost loop's expression is "while True:".
When break statement is executed, the program will start reading the first line of code after the loop.
In the example the last line of code is the 11th line. (Blank line)
After the break the program execution will continue normally.
+ 2
Line 10 will not be executed when 'i' will be 2 and 5.
When i = 2
compiler/interpreter moves inside the if statement and then executes the continue statement which is used to skip an iteration of a loop. So any thing written after continue statement will be skipped.
When i = 5
Compiler/interpreter moves inside the second if statement. When it executes the break statement, it gets out of the loop.
Break statement is used for loop termination.
Continue statement is used for skipping an iteration.
0
i = 0
while True:
i = i +1
if i == 2:
print("Skipping 2")
continue
if i == 5:
print("Breaking")
break
print(i)
print("Finished")
Why command in line 10 is not executed?
It doesn't matter that goes on in the loop, after instruction "break" stops the loop in any case?