• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Be The JVM (Head First)

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand how we got the output?!!
What's the first output in line 14? how do we calculate what's the value coming out of the loop? line 12?!





Answer is 13 15 x = 6
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In line #11 - you increment the value of y for every iteration in the for loop.

In line #12 - you check whether value of x is greater than 4. If so you increment the value of y.

In line #16 - you check whether value of y is greater than 14, If so then you use the break command to exit the for loop. Once a break is executed the for loop is terminated and the value of y will be 15 outside the for loop..

Try to run below program to understand it. If you work out with a pencil and paper you will understand it better.

 
Tariq Ab
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Sir,

Finally got it. had to read it a couple of times letter by letter.

Now i can go to bed
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic