while(condition)do
end
--1.输出1到100
index = 1
while index <= 100 do
print(index)
index = index + 1
end
--2.实现1加到100
sum = 0
index = 1
while index <= 100 do
sum = sum+index
index = index+1
end
print(sum)
--3.遍历1-100中所有奇数的和
sum = 0
index = 1
while index <= 100 do
if index%2 == 1 then
sum = sum+index
end
index = index+1
end
print(sum)
repeat
(code to execute) --先执行代码段在进行条件判断
until (condition)
--1.输出1到100
index = 1
repeat
print(index)
index=index+1
until index > 100
--2.实现1加到100
sum = 0
index = 1
repeat
sum = sum+index
index = index+1
until index>100
print(sum)
--3.遍历1-100中所有奇数的和
sum = 0
index = 1
repeat
if index%2==1 then
sum=sum+index
end
index=index+1
until index>100
print(sum)
Lua循环结构while循环、repeat 循环_学习笔记03
原文:https://www.cnblogs.com/mengmengxia/p/9147642.html