0

This code might be a bit vague, but this question is regarding an assignment I have to turn in and will be checked for plagerism so I will just give the jist of my problem.

bool x = false;

while (x == false)
{


}
if (conditions)
{
x = true;
}
while (x == true)
{
    if (a == b)
    {
    //....
    }
    else
    x = false;
}

I know this code might be confusing but I'll try my best to explain my problem:

Everything runs fine minus the last part. In my second while loop the condition is x == true, but if the conditions of the if statement (within the while statement) arent satisfied, I want x == false, and I want it to go back to the first while loop for the condition x==false. However, it sets x == false, then ends the program.

Any help is appreciated.

2
Contributors
1
Reply
13
Views
2 Years
Discussion Span
Last Post by rubberman
1

You need an outer loop before the while (x == false) loop and after the end of the while (x == true) loop. IE:

while (true)
{
    while (x == false)
    {
    }
    if (conditions)
    {
        x = true;
    }
    while (x == true)
    {
        if (a == b)
        {
            //....
        }
        else
        {
            x = false;
        }
    }
}

You do need to determine if this outer loop needs another terminating condition. IE, this is a "forever" loop.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.