• Post Reply Bookmark Topic Watch Topic
  • New Topic

HeadFirst ( Page 25) exercise question. Confusion.. can somebody help  RSS feed

 
Imran Sabir
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I am a new bee in java and started to red the HeadFirst java book. On page 25, there is question on right upper side of the book class Exercose1b . the answer is "This will compile with no output bt without a line added to the program, it would run forever". Now when i first look at the code. it should type 7 times Bigx.

I am confused. Is this a typing error in the book or i cannot understand

kindly make me correct

regards
Imran
 
Uli Hofstoetter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're playing kind of Jeopardy (or what was the name of that quiz show, where answers were given and the question was to be found?).

What is the question?
 
Chuck Mondi
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you take a look at the exercise they added x = x + 1 to the while clause. This will increment the value of x in each iteration of the loop. If you never use that statement, x would always be 1, the while statement condition (while x < 10) would never become false (x = 11), the println would never print a value because x would never be greater than 3 and it would run forever.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!