Practical example of a while loop (#21523)

* Practical example of a while loop

Added a practical example of the benefits of a while loop being a condition controlled loop

* Fixed syntax and grammar
pull/20856/head^2
SirDickinson 2018-11-03 21:22:52 -05:00 committed by Manish Giri
parent e50a02c7e7
commit 1fd96b1ebc
1 changed files with 2 additions and 0 deletions

View File

@ -50,6 +50,8 @@ The code will then return to line 3 and repeat until days = > 7
As previously noted, a 'while' loop will run until the conditional logic is false. Because of this, it is important to set a "false" condition within the executable code. If no false is included, the while loop will run infinitely. Use caution when setting logic parameters to prevent the infinite loop unless that is the desired output.
Because `while` loops are conditioned controlled loops, they are great for programs that need to be run for an indefinite number of times. This allows for input to be taken time and time again until the condition is met. A good practical example would be for a game in which the player has the option to try again. Until the player responds with the response that meets the `while` loop condition, the player can continue to play the game, simulating the loop as many times as they please.
#### More Information:
- <a href='https://docs.python.org/3/reference/compound_stmts.html#the-while-statement' target='_blank' rel='nofollow'>Python `while` statement documentation</a>