Jump to content
Sign in to follow this  
Kai

Mistake in one of your Website's informations about C++

Recommended Posts

Hello dear, 

i found one of your websites about the switch case statements in C++. 

It says: 
"If there is a match, the associated block of code is executed."
 
This is not wrong, BUT it is not mentioned later (break statements), that the code ist executed *from the line* of the match (and not only the match codeblock) to the end of the switch block, if there is no break statement. 
"break" does not only save runtime, if you don't use it, you will get some hard to find unexpected behavior in your programs. 
 
Example: 
 
    int i= 7;
    switch (i) 
    {
        case 5: cout << 5 << endl; 
        case 6: cout << 6 << endl; 
        case 7: cout << 7 << endl; 
        case 8: cout << 8 << endl; 
        case 9: cout << 9 << endl; 
    }
 
Output: 
7
8
9
 
Greets
 

Share this post


Link to post
Share on other sites

The best way to make the site staff aware of the problem is to click the "REPORT ERROR" button at the bottom of the page, since they almost never visit the forums.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...