Page 1 of 1

About Question enthuware.ocajp.i.v7.2.848 :

Posted: Sun Jan 20, 2013 4:36 am
by ETS User
Question 15 of 45 in the very easy test.

I am just a bit confused. The answer says to decrement the value k and then compare.

As k = 2, if you decrement the value of k, does it not become 1 and then you compare.

I just dont understand why the answer is not just 1. I do not get why 2 is in the answer if we decremented k before comparison.

Sorry I am probably missing something very basic here.

Re: About Question enthuware.ocajp.i.v7.2.848 :

Posted: Sun Jan 20, 2013 7:43 am
by admin
You are thinking correctly. But you are missing one point that the print statement is present even before the while condition. So, first you enter the do block, print k (which is 2 at this point), and then evaluated the while condition. As a part of evaluating the while condition, you first decrement k (because of --k), so now k becomes 1. since 1 is > 0, you go back to the do block. print k (which is 1), and then evaluated the while condition....and so on.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.848 :

Posted: Mon Jan 28, 2013 2:50 am
by Guest
That's great, thanks very much Paul.