’15 -’16 General Discussion for Lesson 5.11

Use this thread to discuss your questions and comments about how to run the lesson.

I had to spend a bit of extra time discussing and working with the how and why a WHILE loop is not an “UNTIL” loop – the distinction between the two and the use of the NOT was a bit confusing.

I can imagine that I will need to spend a couple of days on this lesson. How dd people explain the difference between why using an “or” statement resulted in an infinite loop versus the use of “and”?

I’ll only chime in that logic can be a tricky thing - and that’s really the big point - because it doesn’t always map to the way we say things in English. Whether you use a while loop or a repeat until, there are scenarios that are confusing to construct for both. Humans in general (myself included) have a hard time with NOT when combined with other logic. I find it useful to read NOT out loud as: “it is not the case”.

Then recognize that for OR, it means if any one of these conditions is true, and and AND means if "every one* of these conditions is true. So for a convoluted example:

while ( !(flips > 200) && heads < 20)

You could say…

  • there is an AND here so EVERY ONE of these conditions must be true in order for the loop to run one more time.
  • Condition 1: “it is not the case that flips is greater than 200”
  • Condition 2: “heads is less than 20”

From there you could work up to realizing that this is saying: continue to loop as long as I haven’t flipped 200 times or gotten 20 heads"

Hope this helps.

-Baker