I have this code…
void drawMap(void)
{
if (false)
return;
for(auto iter = this->m_layers.begin(); iter != m_layers.end(); ++iter)
{
if ((*iter)->get() == NULL)
continue;
PN::draw((*iter)->get(), b2Vec2(0,0), true, 0);
}
}
If I’m not mistaken it should NEVER execute…but it does…and when I change
if (false)
return;
to
if (false)
return;
else
return;
it doesn’t execute at all now, but how can that first statement NOT be false? grabs headache pills
P.S. I only did this ’cause I was debugging and noticed my code was drawing to the screen when it wasn’t supposed to.
if (false)will never execute its body… because the value of the condition is never true. So in the code you’ve given, the remainder ofdrawMapwill always execute because it will never return at the start.Consider
if (x == 5)– that will only execute if the expressionx == 5is true. Now substitutefalseforx == 5…If you want an
ifstatement which will always execute, you wantinstead.