Returning false

Look at the following code:


if (!GameEngine::GetEngine()->Initialize(iCmdShow))
return FALSE;

// Enter the main message loop
while (TRUE)
{
}


If the first if statement does in fact return FALSE would the following while statement be carried out or does it stop any following statements from being executed if a FALSE has been returned?
"return" does what it says. It stops the execution of the function and returns to the place the function was called from.

PS: it's [code ] yourcode [ /code], not
[code ] [ /code] yourcode [code ] [/code]
Why not just have

1
2
3
4
5
6
7
8
9
bool running = true;

if (!GameEngine::GetEngine()->Initialize(iCmdShow))
  running = false;

while (running)
{
  //HAI!
}
Last edited on
You don't even know what his code is supposed to do, why suggest a change?
I don't?
Unless you are him, no. Maybe this is inside a function with client code that has error handling for the case it returns false, for instance. You don't know, do you?
He didn't say it was in a function. So I assumed that it isn't.
It is in a function either way, the question is just where that function is called from and what the caller expects as return value.
Exactly
closed account (z05DSL3A)
I think I need some strong drink to make this thread make sense.
Haha. Ok, so if a FALSE was returned while() would not be executed :)
That's right, because the return statement terminates the function right there, and any code after that isn't executed.
Topic archived. No new replies allowed.