break关键字
1、break關鍵字用于 while、for 循環時,會終止循環而執行整個循環語句后面的代碼。break 關鍵字通常和 if 語句一起使用,即滿足條件時便跳出循環。這里強調一下,如果存在多層循環的時候,break只會跳出當前循環;下面是測試多層循環的情況
QList<int> listInt;listInt << 2 << 8 << 9 << 10;QList<int> tempList;tempList << 2 << 10 << 8 << 9;QList<int> newList;for (int index = 0;index <listInt.count();index++) {int tempInt = listInt[index];qDebug() << "index:" <<index << "tempInt:" << tempInt;for (int section = 0;section <tempList.count();section++) {int sectionInt = tempList[section];qDebug() << "section:" << section << "sectionInt:" << sectionInt;if(tempInt == sectionInt){newList.append(sectionInt);qDebug() << "section相同";break;}}}qDebug() << "newList:" << newList;打印輸出截圖如下:
感興趣的人,可以自行測試。
總結
- 上一篇: 从外网访问内网Epson爱普生无线打印机
- 下一篇: 程序员跳槽全攻略(路漫漫其修远兮)