-
Break
(計算機語言關鍵字)
鎖定
- 中文名
- 跳出循環、結束
- 外文名
- Break
- 類 型
- 計算機語言
- 作 用
- 終止所在層的循環,設置斷點
- 屬 性
- 保留字
目錄
Break計算機DOS命令
作用:設置或清除DOS系統的擴展ctrl+c檢測
(1)這個命令是為了與DOS系統的兼容而保留的,在Windows XP裏不起作用;
BreakPHP break
break 結束當前 for,foreach,while,do-while 或者 switch 結構的執行。
<?php $arr = array('one', 'two', 'three', 'four', 'stop', 'five'); while (list (, $val) = each($arr)) { if ($val == 'stop') { break; /* You could also write 'break 1;' here. */ } echo "$val<br />/n"; } /* Using the optional argument. */ $i = 0; while (++$i) { switch ($i) { case 5: echo "At 5<br />/n"; break 1; /* Exit only the switch. */ case 10: echo "At 10; quitting<br />/n"; break 2; /* Exit the switch and the while. */ default: break; } } ?>
BreakJavaScript break
有兩種特殊的語句可用在循環內部:break 和 continue。
Break
break 命令可以終止循環的運行,然後繼續執行循環之後的代碼(如果循環之後有代碼的話)。
實例
<html> <body> <script type="text/javascript"> var i = 0for(i = 0; i <= 10; i++) { if (i == 3) { break } document.write("The number is " + i) document.write("<br />") } </script> </body> </html> //結果 //The number is 0The number is 1The number is 2 //The number is 0The number is 1The number is 2
Continue
continue 命令會終止當前的循環,然後從下一個值繼續運行。
實例:
<html> <body> <script type="text/javascript"> var i = 0for(i = 0; i <= 10; i++) { if (i == 3) { continue } document.write("The number is " + i) document.write("<br />") } </script> </body> </html>
結果:
The number is 0The number is 1The number is 2The number is 4The number is 5The number is 6The number is 7The number is 8The number is 9The number is 10
BreakC語言中的break
break語句通常用在循環語句和開關語句中。當break用於開關語句switch中時,可使程序跳出switch而執行switch以後的語句;如果沒有break語句,則會從滿足條件的地方(即與switch(表達式)括號中表達式匹配的case)開始執行,直到switch結構結束。
例:
main() { int i=0; char c; while(1) /*設置循環*/ { c='\0'; /*變量賦初值*/ while(c!=13&&c!=27) /*鍵盤接收字符直到按回車或Esc鍵*/ { c=getch(); printf("%c\n",c); } if(c==27) break; /*判斷若按Esc鍵則退出循環*/ i++; printf("The No. is %d\n",i); } printf("The end"); }
注意:
1. break語句對if-else的條件語句不起作用。
2. 在多層循環中,一個break語句只向外跳一層。
BreakLinux下GDB調試
作用:設置斷點(BreakPoint)
我們使用break命令來設置斷點,break在進入指定函數時停住。C++中能使用class::function或function(type,type)格式來指定函數名。
break
在指定行號停住。
break +offset
break -offset
在當前行號的前面或後面的offset行停住。offiset為自然數。
break filename:linenum
在源文件filename的linenum行處停住。
break filename:function
在源文件filename的function函數的入口處停住。
break *address
在程式運行的內存地址處停住。
break
break命令沒有參數時,表示在下一條指令處停住。
break…if
…能是上述的參數,condition表示條件,在條件成立時停住。比如在循環境體中,能設置break if i=100,表示當i為100時停住程式。
info breakpoints [n]
info break [n]