Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Break use in while

 
yogesh doshi
Ranch Hand
Posts: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why it prints 0 to 4 can anyone make to understand ??
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what is happening:
  • First time through the loop: c is 0 so prints 0. The if statement is false so c becomes 1
  • First time through the loop: c is 1 so prints 1. The if statement is false so c becomes 2
  • First time through the loop: c is 2 so prints 2. The if statement is false so c becomes 3
  • First time through the loop: c is 3 so prints 3. The if statement is false so c becomes 4
  • First time through the loop: c is 4 so prints 4. The if statement is true so breaks out of the loop with label JACK. There is nothing after that so the program ends
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic