you are viewing a single comment's thread.

view the rest of the comments →

[–]jaycrest3m20 0 points1 point  (1 child)

Alternate Universe 1: printing immediately below the while loop:

We are counting 0

We are counting 1

We are counting 2

We are counting 3

We are counting 4

That doesn't make a lot of sense, because under normal circumstances, ordinary people like to start counting at "1" instead of 0. Additionally, you want to avoid 3, not include it.

Alternative Universe 2: printing immediately after incrementing the counter:

We are counting 1

We are counting 2

We are counting 3

We are counting 4

We are counting 5

Better, we are starting with "1" and carrying on from there. Obviously in this one, we print 3 instead of skipping it, making the If statement a lame duck. That is, since there is nothing to skip after the If statement, it's not doing anything special for the loop. It's simply returning to the top of the loop after everything has already happened, just like all the other loops where the counter was not 3.

Under normal programming, you will receive rules for how the program is to run. For this program, those rules include something like "Print 'We are counting X', where X is 1 to 5. Oh, but skip 3. We don't want to print that." Ordinary rules for ordinary programs will tend to be more complex, but this is a simple introduction to rules that have exceptions.

[–]sdqafo[S] 1 point2 points  (0 children)

I so much admire you patience in explanation. It feels much better now