While Loops

while loop in Python programming repeatedly executes a target statement as long as a given condition is true. If found this chart and want to show it to you as it describes the way of using while-loops pretty good:

Chart found on: https://www.tutorialspoint.com/python/python_while_loop.htm

So what we can see is that you define a condition and if it turns true the assigned conditional code will be executed otherwise the loop ends.

In most soccer stadiums in Germany the stadium announcer calls the name of every player at least 3 times and the fans have to repeat them everytime. For the best players the fans shout “Fußballgott” (god of soccer) three times. How can we implement this in Python:

The “+=” adds one to the varible i with every iteration until the condition turns to false

The next thing I want you to understand is how loops into loops function. Imagine the stadium announcer says the name of the player one time than the fans scream “Fußballgott” three times and then the stadium speaker says the name one more time:

Methaporically spoken, when the fans beginn to sign it is first their turn to finish their part until its the announcers turn again. So first the inner loop will be completed until it jumps back to the outer part.

I hope you understood the basic functionality of the while loop. If you want to get further information e.g. what to do with the “break” or the “continue” into a loop have a look at this resource:

https://realpython.com/python-while-loop/

#Mastery13

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s