switch中使用continue和break

如果你在switch中使用continue,continue生效是对于while循环
如果你在switch中使用break,break生效是对于switch。

如果在switch外使用continue和break,生效都是对于while循环。
写个程序什么都清楚了。

-------------------------------------------------------
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
    int ix;
    while( cin >> ix )
    {
        switch(ix)
        {
            case 1:
                cout << "u input 1 and break" << endl;
                break;
            case 2:
                cout << "u input 2 and continue" << endl;
                continue;
            default:
                cout << "if continue then default..." << endl;
                break;
        }
        cout << "after switch ix: " << ix << endl;
    }
  
  system("PAUSE");
  return 0;
}

猜你喜欢

转载自blog.csdn.net/jfkidear/article/details/88947104
今日推荐