Do while scoop error

I always forget how to do this the correct way, and always end up whith the same error. Its a simple problem, and I'm sure the solution is very obvious.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main()
{
    do
    {
        int foo = baz();    // return value

        switch(foo)
        {
            case 1:
                //...
                break;
            case 2:
                //...
                break;
            //...
            default:
                //...

        }//END switch

    }while(foo != 0);    //END do while    <-ERROR

}//END main 


Error:

'foo' was not declared in this scope


I know variables only survives inside the scope, but how do I get pass this problem?

The baz() function is a menu which I want to be displayed using the do while loop. And the return value (the menu choice) should be tested in the switch...
foo is declared inside of the scope of the do-while loop.
That is to say that it's lifetime is confined to the {} of the loop.

Either move it so that it's above to do command or pick another while condition.
Thank you iHutch105
Topic archived. No new replies allowed.