Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loop Doubt  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want the output as
""HiHelloHiHelloBye"
But I am getting only "HiHelloHiHello"
I dont know why the content inside the if loop is not read.
 
author & internet detective
Sheriff
Posts: 38050
606
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the time you get to if (x ==1), x is no longer 1. You can verify this by adding System.out.println(x) to the line before the "if."

ps - It's called an "if statement" and not an "if loop"
 
lowercase baba
Bartender
Posts: 12613
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:By the time you get to if (x ==1), x is no longer 1. You can verify this by adding System.out.println(x) to the line before the "if."


I'd also put on inside the while loop, so you can see it changing in there.
 
Karthikeyan Pandian
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah , now I unserstood

Thank you friends...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!