any way to run a while loop after an if statement without using else?

Sep 27, 2011 at 11:37pm
I want to check something in an if statement, then regardless of its result run a while loop after. and I can't just use

1
2
3
4
5
6
if (statement){
//code
}
while(statement){
//code
}

as this doesn't seem to work... any way to do this?
Last edited on Sep 27, 2011 at 11:46pm
Sep 27, 2011 at 11:44pm
one of the end brackets is commented out.

1
2
3
4
5
if (statement){
//code}
while(statement){
//code
}


should be more like
1
2
3
4
5
6
if (statement){
//code
}
while(statement){
//code
}

Sep 27, 2011 at 11:48pm
yeh sorry that's not what I meant at all, that's just a glitch in my example :)
what I want is for my method to test an if statement first, then run a while loop after regardless of the result from the if statement. they're independant, but I need to run both in my method, so can't use else to get it going.
also tried using a goto, but that doesn't change anything. goto isn't something I want in my program either really.
Last edited on Sep 27, 2011 at 11:51pm
Sep 27, 2011 at 11:58pm
What you are doing in your first post is exactly right, and will work just fine.

If your while loop is not running, it's because the condition is coming back false.
Sep 28, 2011 at 12:04am
seems my if statement is the problem then :) only problem is the same if statement works perfectly in another method :/
Last edited on Sep 28, 2011 at 12:05am
Sep 28, 2011 at 12:08am
u cud put the if statement inside the while loop. but if you only want it triggered once, do nested ifs.

1
2
3
4
5
6
while(){
if(ex. i = 1 or something that will only happen once){
      if(the statement you only want to test once){
      }
}
}


don't know what else to tell ya ... more explanation would help but I hope thats what your looking for
Sep 28, 2011 at 12:46am
-- removed since resolved
Last edited on Sep 29, 2011 at 2:27am
Topic archived. No new replies allowed.