Lua循环结构while循环、repeat 循环、for循环_学习笔记03
Lua循环结构while循环、repeat 循环、for循环
while语法结构
while 循环条件 do
循环体
end
--1.输出1到100 index =
while index <= do
print(index)
index = index +
end --2.实现1加到100 sum =
index =
while index <= do
sum = sum+index
index = index+
end
print(sum) --3.遍历1-100中所有奇数的和
sum =
index =
while index <= do
if index% == then
sum = sum+index
end
index = index+
end
print(sum)
repeat循环语法结构
repeat
循环体 --先执行代码段在进行条件判断
until 循环条件
--1.输出1到100 index =
repeat
print(index)
index=index+
until index > --2.实现1加到100 sum =
index =
repeat
sum = sum+index
index = index+
until index>
print(sum) --3.遍历1-100中所有奇数的和 sum =
index =
repeat
if index%== then
sum=sum+index
end
index=index+
until index>
print(sum)
for循环的语法结构
--初始值,终止值,步长 三个部分只会被执行一次。
--所以即使在循环体重不小心改变了终止值和步长,循环也能正常结束(还是原来的终止值 和步长 )
--在使用for循环时,需要注意 (1)循环次数只在第一次执行时确定,用户更改了参数值也不会影响最终的循环洗漱
--(2)循环结构为局部变量,一旦循环结束就会被清除
for 变量 =初始值,终止值,步长 do --步长 可以省略,默认为 1
循环体
end
--1.输出1到100 index =
for index = , do print(index) end --2.实现1加到100 sum =
index =
for index = , do
sum = sum+index
end
print(sum) --3.遍历1-100中所有奇数的和 sum =
index =
for index = , do
if index%== then
sum=sum+index
end end
print(sum)
--有 1,2,3,4四个数字,能组成多少个互不相同且无重复数字的 三位数,并输出在屏幕上面
for i = , , do
for j = ,, do
for p = , , do
if i ~= j and i ~= p and j ~= p then
print(i..j..p)
end
end
end
end
Lua循环结构while循环、repeat 循环、for循环_学习笔记03的更多相关文章
- .Net基础篇_学习笔记_第五天_流程控制while循环
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- .Net基础篇_学习笔记_第四天_if结构
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 循环结构——while、do-while、for循环
1.while循环 语法格式: while(条件判断){ 循环体 } 解释: (1)关键字while后的小括号中的内容时循环条件. (2)循环条件是一个布尔表达式,它的值为布尔类型 "真&q ...
- .Net基础篇_学习笔记_第六天_for循环的几个练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- .Net基础篇_学习笔记_第六天_for循环的嵌套_乘法口诀表
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- .Net基础篇_学习笔记_第六天_for循环语法_正序输出和倒序输出
for TAB 和 forr TAB using System; using System.Collections.Generic; using System.Linq; using System. ...
- .Net基础篇_学习笔记_第六天_For循环语法
For循环:专门处理已知循环次数的循环. 小技巧:连续敲击两下TAB键循环体自动搭建完成. For循环语法: for(表达式1;表达式2;表达式3){ 循环体;}表达式1一般为声明循环变量,记录循环 ...
- .Net基础篇_学习笔记_第五天_流程控制do-while循环
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- .Net基础篇_学习笔记_第五天_流程控制while循环003
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
随机推荐
- 一个oracle bug
最近发现一个RAC db的listener log增长特别快,于是去查看了一下. 先是查看了一下log的内容,发现都是 service_update这种内容,刷新的特别快. service_updat ...
- Clojure:两步发送iOS推送通知(apns)
首先在project.clj中,添加对notnoop 类库的引用:[com.notnoop.apns/apns "0.2.3"] 然后使用如下方法就可以发送推送消息了: (ns d ...
- RxJava资料整理
RxJava资料整理 https://www.jianshu.com/p/e3c4280ce397 http://www.daidingkang.cc/2017/05/19/Rxjava/ http: ...
- LeetCode 122 Best Time to Buy and Sell Stock II(股票买入卖出的最佳时间 II)
翻译 话说你有一个数组,当中第i个元素表示第i天的股票价格. 设计一个算法以找到最大利润. 你能够尽可能多的进行交易(比如.多次买入卖出股票). 然而,你不能在同一时间来多次交易. (比如.你必须在下 ...
- android获取当前软件版本号号和版本号名称
<span style="font-size:18px;">/** * 获取本地软件版本号 */ public static int getLocalVersion(C ...
- HDU1698 Just a Hook 【线段树】+【成段更新】+【lazy标记】
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- LeetCode OJ 之 Valid Anagram
题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example, s ...
- 分享微软官方Demo用的SharePoint 2010, Exchange 2010, Lync 2010虚拟机
微软官方有一套专门用于SharePoint 2010, Exchange 2010 Demo的虚拟机:SharePoint 2010: Information Worker Demonstration ...
- 一条SQL语句求前面记录的平均值
有算法要求如下: For (i=1,i<=10,i++) { ta[i] = (t[1] + t[2] + ... + t[i]) / i; } 用一条SQL语句实现它: 分别用表变量 @ta ...
- GDI+学习之------色彩与图像
色彩 在GDI+中.色彩是通过Color类来描写叙述的.不是用RGB类.用RGB构造会出错.GDI+中的色彩信息值是由一个32位的数据来表示的,它包含8位alpha值和各8位的R.G.B值,对于alp ...