From the course: Certified Entry-Level Python Programmer (PCEP-30-02) Cert Prep

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Changing the natural flow in loops

Changing the natural flow in loops

- [Instructor] So far we've seen two different kinds of loops. We have the while, for example, I can ask the user to enter a number and I will check while what the user is entering is different, that the character zero. I'm going to repeat something such as print, nice number. And also we've seen the for where I can, for example, use range as a sequence generator where I'm going to print the value. So if I run this, it's asking me for a number, nice number until I enter zero. And after that it's executing the four 50 times from zero to forty-nine. So, so far we know how these loops work. One is based on a condition and the other one will go always through all the sequence. But there is a way to change this natural flow in loops and that way it's something like this. For example, let me comment the why and work for the four. So that means that now every time I'm running this, it's just printing 50 numbers. But what if…

Contents