Friday, September 9, 2011

Challenge 008

The output ends up to be -1.

We name the value "num"

The initial value starts out to be 5. int num = 5;

The while loop tells us that the value will decrease by an interval of 2 and that the loop will continue to do so until the value turns out to be less than 0.
The next line tells us that the interval is to decrease by -2 num -= 2;

This tells us that the value most be -1 because it cannot pass -2 and the value has to be less than 0.

3 comments:

  1. We'll start with these two statements:

    "The while loop tells us that the the value needs to be less than 0. while ( num >= 0)"

    "The next line tells us that the interval is to decrease by -2 and cannot go as far as -2 num -= 2;"

    Both have technical inaccuracies that do not reflect the reasons for the observed behavior. Please revise.

    Thank You.

    ReplyDelete
  2. The loop is telling you that as long as the statement (value => 0) is true, it will continue subtracting 2 from the number. Once the statement is no longer true, the loop stops. The compiler then spits out the value when the loops ends which comes out to be -1

    ReplyDelete
  3. Now we're talkin', 15 XPs for this completion.

    ReplyDelete