[RESOLVED] Strangley placed else
In this code snippet what does the line (line 20) that reads
cause to the flow of the program, if anything? If it does nothing why would someone have it there?
Code:
mode = -1;
while ( /* read a line from a file */ )
{
if (mode<0)
{
// Do something for when mode < 0
}
else if (mode==0)
{
if ( /* some condition */ )
{
mode=1;
continue;
}
else if ( /* some other condition */ )
{
// Code for some other condition
}
else ; <<-- What does this do?
}
else // mode is 1
{
// A lot of code for mode 1
} // end mode=1 code
}
// Code after the while loop
Thanks.
Re: Strangley placed else
It does nothing. Most likely there to remind the programmer that there is other cases besides the two specified.
Re: Strangley placed else
Re: [RESOLVED] Strangley placed else
Some coding rules (Misra for instance) requires that all if-statements are complete i.e. there should always be an else even when it's not needed.