Computer Science Canada if statements and loop |
Author: | iluvchairs112 [ Wed Apr 04, 2007 7:19 pm ] |
Post subject: | if statements and loop |
this is probably really basic, but I can't seem to figure it out (and I'm kinda new to Java anyway) so, if I have a couple of if-statements and I want them to repeat. like if one becomes untrue then go on to the next one. if that is untrue then go on to the next one. then if the third one is untrue, go back to the top. i've tried experimenting with it, but can't figure it out. |
Author: | Geostigma [ Wed Apr 04, 2007 7:44 pm ] |
Post subject: | RE:if statements and loop |
I don't know how java works but you need a else or elsif style command. |
Author: | rdrake [ Wed Apr 04, 2007 8:14 pm ] | ||||
Post subject: | Re: if statements and loop | ||||
iluvchairs112 @ Wed Apr 04, 2007 7:19 pm wrote: this is probably really basic, but I can't seem to figure it out (and I'm kinda new to Java anyway)
Take a look at the while and do while loops.
so, if I have a couple of if-statements and I want them to repeat. like if one becomes untrue then go on to the next one. if that is untrue then go on to the next one. then if the third one is untrue, go back to the top. i've tried experimenting with it, but can't figure it out. While: While the condition is true, the while loop happily repeats itself.
Do While: While the condition is true, the do while loop also happily repeats itself. Difference here is the code block is executed at least once, even if the condition is false to begin with.
Note: I'm honestly not sure if that last semi-colon should be there or not. Get rid of it if the compiler throws a fit over it. |
Author: | ericfourfour [ Wed Apr 04, 2007 8:33 pm ] | ||
Post subject: | RE:if statements and loop | ||
Or if you want some simple infinite loops:
|
Author: | iluvchairs112 [ Thu Apr 05, 2007 5:46 am ] |
Post subject: | RE:if statements and loop |
is there something like a while else statement? i know there is if else and i know there is while ... |
Author: | richcash [ Thu Apr 05, 2007 9:19 am ] | ||
Post subject: | Re: if statements and loop | ||
Can't you do this?
where cond and someOtherCond are obviously boolean expressions |
Author: | klopyrev [ Thu Apr 05, 2007 1:40 pm ] | ||||
Post subject: | Re: if statements and loop | ||||
I don't get what you are trying to do. Explain more clearly. You are either trying to do this:
OR
But then again, I don't really understand what you are trying to do. KL |
Author: | FileFantasy [ Fri Apr 06, 2007 9:22 pm ] | ||
Post subject: | Re: if statements and loop | ||
Don't really know what you mean, but from what you described, this is what I got:
However, I don't know how the statements will become true if they're not true the first time around. |
Author: | ericfourfour [ Fri Apr 06, 2007 11:48 pm ] |
Post subject: | RE:if statements and loop |
Using the allUntrue variable is pretty tedius. A simple break; will end the loop. |
Author: | FileFantasy [ Sun Apr 08, 2007 7:30 pm ] | ||
Post subject: | Re: if statements and loop | ||
That's true, and this is what ericfourfour means:
|