INTERACTIVE ONLINE COURSE

Python 3

FOR BEGINNERS


"The first Python course that simply amazed me. Very well explained and easy to understand." (Alexandru Cosmin)

"The best Python course in Romania." (Iulian Geană)


ALL REVIEWS
THEORY
PAGE 1 / 1
break And continue Clauses
Home >>> Online Lessons, Python 3

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.
 home   list  CONTENTS   perm_identity   arrow_upward