# repeat if statement in loop

• 03-05-2012, 12:58 PM
eng_hyzoom
repeat if statement in loop
i want help in repeating if statement in loop
i mean if it is a loop and has inner if statements this problem occur ...
if first condition hold enter first if body then repeat loop
when repeating the loop first condition is still hold it enter again in first if body
and repeat again and so on
loop becomes infinite loop because first if statement usually hold
i want after entering first if in second iteration it enters in next if
i hope you are understand me :)-:
• 03-05-2012, 01:06 PM
fatabass
Re: repeat if statement in loop
• 03-05-2012, 01:18 PM
eng_hyzoom
Re: repeat if statement in loop
Quote:

Originally Posted by fatabass

thanx fatabass
for example
int x=3;
int y=2;
int z=1;
boolean ok = true;
while(ok){
if(x>y){
x=4;
y=3;
System.out.println("hello");
}
else if(y>z){
x=4;
y=3;
}
}
this infinite loop i want after finishing first if check second one and so on
• 03-05-2012, 01:19 PM
JosAH
Re: repeat if statement in loop
Quote:

Originally Posted by eng_hyzoom
i hope you are understand me :)-:

Erm ... no, sorry.

kind regards,

Jos
• 03-05-2012, 01:26 PM
eng_hyzoom
Re: repeat if statement in loop
Quote:

Originally Posted by JosAH
Erm ... no, sorry.

kind regards,

Jos

thanx Jos
try this example and try to solve it
int x=3;
int y=2;
int z=1;
boolean ok = true;
while(ok){
if(x>y){
x=4;
y=3;
System.out.println("hello");
}
else if(y>z){
x=4;
y=3;
}
}
• 03-05-2012, 01:34 PM
Tolls
Re: repeat if statement in loop
Then you need some way for the code to know it has already done 'x>y'.
At the moment there is nothing there to say.

TO be honest, I suspect your problem lies not in this, but in whatever it is you are actually trying to do that this is the apparent solution.