Author | Message |
---|---|
Rochester123
Posts: 5
|
Posted 22:55 Feb 21, 2014 |
In the input validation class for udacity, isn't it logical to put : while (value <= 100); than while (value >= 100);? |
rabbott
Posts: 1649
|
Posted 23:36 Feb 21, 2014 |
Think about what this code will do if value is < 100. while (value < 100); It will repeatedly print: "thank you" + value. In other words, it will be an endless loop. The example code while (value >= 100) { will remain in the loop while the user enters unacceptable numbers. The loop terminates when the user enters a number that is < 100. This may seem somewhat backwards. The loop repeats while something is wrong. Normally you think of a loop repeating to accomplish something positive. This example uses loops in a negative way. But it is correct. |