Hello, I just have a quick question, I have two while loops that don't quite do what I want

while (e == true && num != 1) { do statement }
while (e == false && num !=1) { do different statement } 
if (num == 1) { System.out.println(value); }

What I want to happen is while e is true do the statement until e is false, then I want it to go through the second while loop and while e is false do that statement, which is does, HOWEVER I want it to keep going through both of these loops until the variable num gets to 1, ONLY then do I want it to stop. however at the moment it just loops through the first one until e is false then moves to the second, loops through that until e is true then stops, doesn't go back to the first while loop

Can anyone help me out? Thank you!

Recommended Answers

All 2 Replies

nest your while loops:

while (num != 1){
while (e == true && num != 1) { do statement }
while (e == false && num !=1) { do different statement } 
}
System.out.println(value);

something like that might help you out.

Thank you, that did it! That was driving me insane lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.