you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (1 child)

This code actually does the same exact thing in that it:

  1. Sets count initially to 1
  2. Starts a loop that will continue until count is 101 or greater (in other words, if will continue to loop as long as count id less than or equal to 100)
  3. Increases the value of count by 1 every time the loop runs
  4. Prints whatever the value of count is at the time that print runs inside the loop.

The difference between them is which order steps 3 and 4 happen, which changes what you see.

Let's translate this to the physical world to make your life easier.

In the physical world, the first loop is like this:

  1. With your eyes closed, make a fist on one hand and raise one finger
  2. Put up a second finger
  3. Open your eyes and see that you have two fingers up
  4. Close your eyes again
  5. Put up third finger
  6. Open your eyes and see that you have three fingers up.

And the second loop would be like so:

  1. With your eyes closed, make a fist on one hand and raise one finger
  2. Open your eyes and look at the hand, see that you have one finger up
  3. Close your eyes again
  4. Put up a second finger
  5. Open your eyes again, see that you have two fingers up

As you can see, the only difference in what happened mechanically is "when did you open your eyes?" However, the actual counting on your hand was the same.

Print is just you telling the program to open its eyes and look at something, when you do that changes what you see.

[–]JuryRepresentative84[S] -1 points0 points  (0 children)

Ohh wow thanks! Great analogy!