MATLAB while循环

while循环重复执行语句,当条件为 true。

语法:

在MATLAB 中 while循环的语法是:

while <expression>
   <statements>
end

while 循环反复执行程序语句只要表达式为 true。

表达式是 true,当结果不为空,并包含所有非零元素(逻辑或实际数字)。否则,表达式为 false。

例子

创建一个脚本文件,并键入下面的代码:

a = 10;
% while loop execution 
while( a < 20 )
  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: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3