Created
March 8, 2015 12:44
-
-
Save yxjxx/8f0f68d7751fd1037be5 to your computer and use it in GitHub Desktop.
C语言Switch case语句用法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <iomanip> | |
| using namespace std; | |
| int main() | |
| { | |
| int a=0,i; | |
| for(i=1;i<5;i++){ | |
| switch (i){ | |
| case 0: | |
| case 3: //case 3匹配成功之后,因为没有break,其后的语句都会被执行 | |
| a += 2; | |
| case 1: | |
| case 2: | |
| a += 3; | |
| default: | |
| a += 5; | |
| } | |
| } | |
| cout << "a = " << a << endl; | |
| return 0; | |
| } | |
| // result: a = 31 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment