# Thread: repeat if statement in loop

1. Member
Join Date
Oct 2010
Posts
20
Rep Power
0

## 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

2. Senior Member
Join Date
Nov 2011
Location
Turkey
Posts
380
Blog Entries
24
Rep Power
6

3. Member
Join Date
Oct 2010
Posts
20
Rep Power
0

## Re: repeat if statement in loop

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

4. ## Re: repeat if statement in loop

Originally Posted by eng_hyzoom
i hope you are understand me
Erm ... no, sorry.

kind regards,

Jos

5. Member
Join Date
Oct 2010
Posts
20
Rep Power
0

## Re: repeat if statement in loop

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;
}
}

6. Moderator
Join Date
Apr 2009
Posts
13,216
Rep Power
23

## 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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•