How to create a while loop in Python

Computers are much better than the people in performing repetitive tasks over and over again. You can have a great (and sometimes endless) list of programmatic tasks you want done, and while loops in Python lets you perform without having to cut and paste and modify large blocks of code repeatedly .

Create a while loop

Create a suspended sentence to be checked by the while loop. This conditional statement is checked again and again by Python to see if it is true .

realize that while the conditional is true, the code within the body of the while loop will continue running. Using the following example: i = i 0while <5: In the last, declare a variable i initially to be zero. The next line is the beginning of the while loop, in which we say we want a loop that occurs repeatedly while the value of i is less than 5 .

Determine how you will finish the loop. The while loop will run until the sentence is false .

realize that the variables used in the suspended sentence can also be changed within the while loop while it is running. In this example, you simply add a variable to the i every time you go through the loop: i = i 0while <5: i = i 1

Perform any other task you want to repeatedly occur while the loop is running: 0while i = i <5: i i = 1 print “value of i is” i This example of print: the value of i is 1value i is 2value i is 3value i is 4value i is 5

Featured Links:

Google Payload
Proven Money Maker At $9,547 A Day.
Burn The Fat Feed The Muscle
Burn The Fat - Top Selling Fat Loss Ebook Since 2003.
Save My Marriage Today!
Have You Ever Stayed Awake at Night Stressing About Whether or Not Your Marriage Will Last ... And What You Can Possibly Do to Save It?
Ultra Hot* SpywareBot: #1 AntiSpyware
Scan your computer for hidden AdWare and Spyware, Remove them permanently.
Top Movie Downloads
Join the Internet revolution and start downloading free movies and more!
Get Google Pay-Per-Click Ads Free!
Internet Marketer Gets $87 Million in Google Pay-Per-Click Ads FREE! ... And Makes Over $314 Million as a Result! ...And Now He's Going to Give You This Same Secret for Next to Nothing!
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • TwitThis

Leave a comment

You must be logged in to post a comment.