continue
将控制传递给 for
或 while
循环的下一迭代
语法
说明
continue
将控制传递给 for
或 while
循环的下一迭代。它跳过当前迭代的循环体中剩余的任何语句。程序继续从下一迭代执行。
continue
仅在调用它的循环的主体中起作用。在嵌套循环中,continue
仅跳过循环所发生的循环体内的剩余语句。
示例
有选择地显示循环中的值
显示从 1 到 50 的 7 的倍数。如果数字不能被 7 整除,请使用 continue
跳过 disp
语句,并将控制传递给 for
循环的下一迭代。
for n = 1:50 if mod(n,7) continue end disp(['Divisible by 7: ' num2str(n)]) end
Divisible by 7: 7 Divisible by 7: 14 Divisible by 7: 21 Divisible by 7: 28 Divisible by 7: 35 Divisible by 7: 42 Divisible by 7: 49
跳至下一循环迭代
统计文件 magic.m
中的代码行数。使用 continue
语句跳过空白行和注释。continue
跳过 while
循环中的其余指令并开始下一迭代。
fid = fopen('magic.m','r'); count = 0; while ~feof(fid) line = fgetl(fid); if isempty(line) || strncmp(line,'%',1) || ~ischar(line) continue end count = count + 1; end count
count = 37
fclose(fid);
提示
continue
语句跳过for
或while
循环中剩余的说明,并开始下一迭代。要完全退出循环,请使用break
语句。continue
不是在for
或while
循环之外定义的。要退出函数,请使用return
。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)