Monday, November 14, 2011

Challenge 030’s Solution

The subtle error within this code is with how the while statement is written. The coding presents no change to the variable num. Therefore, if num doesn’t equal SENTINEL, the while statement will occur, and since neither variable will change, the while statement will still be true, and repeat indefinitely. This will create lag, with the program continuing to run without progress. To correct this, one must present a command that will change the value of num at the while statement’s end.
 
−Phoenix

5 comments:

  1. The subtle error presented in this scenario will rear its ugly head before we start seeing the behaviors in the while loop that you mention above.

    Your recommendation is another suitable adjustment that needs to be made, but there is a more subtle error present that would need fixed first.

    ReplyDelete
  2. The “int” variable “num” must be a positive integer. However, the “final int” variable “SENTINEL” is equal to −777, and is thus not a good tester for whether or not “num” is > 0. Because of this fragment, the program will run on any “num” values > −777, instead of the intent of running only on values > 0.

    −Phoenix

    ReplyDelete
  3. Hi Phoenix, I completely agree with your take on the sentinel value and the awkward user experience this would produce.

    The error here though is actually going to prevent the program from compiling, and is a very fundamental, and somewhat challenging to spot problem.

    ReplyDelete
  4. The error presented within this code lies with the variable “n”—specifically that its value isn’t defined within the code. Thus, the “while” loop cannot be executed, as it requires the statement “‘num’ ≠ ‘SENTINEL’” to be true to operate; however, “num” has no defined value, so the “while” statement will unintentionally never properly run.

    −Phoenix

    ReplyDelete
  5. Nebulous and clandestine error found and eliminated, Good work. 30 XPs awarded.

    ReplyDelete