-
October 15th, 2012, 03:22 PM
#1
[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.
-
October 15th, 2012, 03:52 PM
#2
Re: Strangley placed else
It does nothing. Most likely there to remind the programmer that there is other cases besides the two specified.
-
October 15th, 2012, 03:56 PM
#3
Re: Strangley placed else
-
October 16th, 2012, 12:41 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|