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.
About Question enthuware.ocajp.i.v7.2.848 :
Moderator: admin
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.848 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 149 guests