Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Not understanding while loop counting

by davido (Cardinal)
on Aug 10, 2020 at 14:59 UTC ( [id://11120546]=note: print w/replies, xml ) Need Help??


in reply to Not understanding while loop counting

Consider the steps

  • Set count to zero.
  • Check if count is less than ten. It is zero.
  • Increment count to one.
  • print count (1)
  • Do this a few more times........then...
  • Check if count is less than ten. It is nine.
  • Increment count to ten.
  • Print count (10)
  • Check if count is less than ten (it is 10, so it is not less)
  • Do not enter loop body; we're done.

See: Off by one error


Dave

  • Comment on Re: Not understanding while loop counting

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found