
详细例子:
在MATLAB中建立一个脚本文件,并输入下述代码:
a = 10;
%while loop execution
while a < 20
if a == 15
% skip the iteration
a = a + 1;
continue;
end
fprintf('value of a: %d
', a);
a = a + 1;
end
运行该文件,显示下述结果:
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19
MATLAB while循环示例
本文通过一个MATLAB脚本示例介绍了如何使用while循环及continue语句来控制循环流程。示例展示了当变量a小于20时,如何打印a的值并跳过特定迭代。
3708

被折叠的 条评论
为什么被折叠?



