Kai Posted January 5, 2020 Share Posted January 5, 2020 Hello dear, i found one of your websites about the switch case statements in C++. https://www.w3schools.com/cpp/cpp_switch.asp 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 Link to comment Share on other sites More sharing options...
Ingolme Posted January 5, 2020 Share Posted January 5, 2020 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. 1 Link to comment Share on other sites More sharing options...
Kai Posted January 23, 2020 Author Share Posted January 23, 2020 Ok sorry, didn't see that. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now