第十八章 循环结构
程序员文章站
2023-12-23 19:05:45
...
for语句
>> for i=1:5
i
end
i =
1
i =
2
i =
3
i =
4
i =
5
>> for i=2:4:14
i
end
i =
2
i =
6
i =
10
i =
14
while语句
>> a=5;
while a<10
a
a=a+1;
end
a =
5
a =
6
a =
7
a =
8
a =
9
continue语句
结束本次循环,进入下一轮循环。
>> for i=1:5
if i==3
continue
end
i
end
i =
1
i =
2
i =
4
i =
5
break语句
结束循环
>> for i=1:100
if i==3
break
end
i
end
i =
1
i =
2