[RESOLVED] Strangley placed else
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Strangley placed else

  1. #1
    Join Date
    Oct 2007
    Posts
    31

    [RESOLVED] Strangley placed else

    In this code snippet what does the line (line 20) that reads

    Code:
    else ;
    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.

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Strangley placed else

    It does nothing. Most likely there to remind the programmer that there is other cases besides the two specified.

  3. #3
    Join Date
    Oct 2007
    Posts
    31

    Re: Strangley placed else

    Thanks very much.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,634

    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.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center