| MATLAB Function Reference | ![]() |
Syntax
break
Description
break
中止 for 廻圈或
while 廻圈的執行。在巢狀廻圈中, break 會結束最內層的廻圈。
Remarks
在MATLAB的副本或函式中,若在for 或 while
廻圈之外使用 break ,會立刻結束副本或函式的執行。
若 break 在 if, switch-case, try-catch
指令中執行,會中止執行這些指令。
Examples
下列範例為利用 while 廻圈將 fft.m
中的字讀進字元陣列中。當讀到第一個空白行時,利用 break 指令來跳出 while
廻圈。最後所得到的字元陣列中也包括了 fft.m 檔案的求助資料。(The
resulting character array contains the M-file help for the fft program.)
fid = fopen('fft.m','r');
s = '';
while ~feof(fid)
line = fgetl(fid);
if isempty(line), break, end
s = strvcat(s,line);
end
disp(s)
See Also
| box | brighten | ![]() |