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

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

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
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.
seems my if statement is the problem then :) only problem is the same if statement works perfectly in another method :/
Last edited on
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
-- removed since resolved
Last edited on
Topic archived. No new replies allowed.