break And continue Clauses
The break Clause
If we want to force an exit from a repetitive cycle, either
for or
while, we can use
break.
Example. Suppose we have a list of several strings (type
str). The cycle stops when the string "
d" is encountered:
When the variable
x received the value of the element "
d", the condition within the
if was met,
and
break was executed – the
for loop
ended immediately, even though there were more elements to evaluate and values to print.
The continue Clause
Sometimes we may want
certain values to skip the entire set of instructions subordinated to the repetitive cycle (i.e., the current iteration):
In this case, when the element "
d" was encountered, it was not printed, but the next iteration of the
for
loop was initiated (specifically, the
print function was not executed).
This section is over now.