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 ...
随机推荐
- HDU 4503
可以反过来求不是相同关系的小朋友.相当于染色问题吧. 对于A小朋友,它的T个朋友和另外的(N-1-T)个同学就可以组成一个这样的三角形.T*(N-1-T),由于一条非染色边被计算两次,所以除以2. # ...
- ZZUOJ-1195-OS Job Scheduling(郑州大学第七届ACM大学生程序设计竞赛E题)
1195: OS Job Scheduling Time Limit: 2 Sec Memory Limit: 128 MB Submit: 106 Solved: 35 [id=1195&quo ...
- EarthWarrior3D游戏ios源代码
这是一款不错的ios源代码源代码,EarthWarrior3D游戏源代码. 而且游戏源码支持多平台. 适用于cocos v2.1.0.0版本号 源代码下载: http://code.662p.com/ ...
- 传智播客C/C++学员荣膺微软&Cocos 2d-x黑客松最佳创新奖
6月30日,历时32小时的微软开放技术Cocos 2d-x 编程黑客松在北京望京微软大厦成功落下帷幕,这是微软开放技术首次联合Cocos 2d-x 在中国举办黑客松. 此次活动共同拥有包含传智播 ...
- [Codeforces 1013B] And
[题目链接] http://codeforces.com/problemset/problem/1013/B [算法] 不难发现,答案只有0,1,2,-1,共4种取值 分类讨论即可,计算时可以使用ST ...
- B3109 [cqoi2013]新数独 搜索dfs
就是基于普通数独上的一点变形,然后就没什么了,普通数独就是进行一边dfs就行了. 题干: 题目描述 输入格式 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第 ...
- 关于api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案
关于api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案 目录 关于api-ms-win-crt-runtimel1-1-0dll缺失的解决方案 目录 安装VC redite ...
- Swagger UI改造 增加 Token验证、显示控制器注释、自定义泛型缓存应用、
/// <summary> /// Swagger 增加 Token 选项和控制器描述 /// </summary> public class CustomOperationF ...
- 模拟Queue(wait/notify)
BlockingQueue:顾名思义,首先它是一个队列,并且支持阻塞的机制,阻塞的放入和得到数据.我们要实现LinkedBlockingQueue下面的两个方法put和take. put(anObje ...
- ACM_开心消消乐
开心消消乐 Time Limit: 2000/1000ms (Java/Others) Problem Description: 大白最近喜欢上了开心消消乐,于是英语基础好的他准备让课文中英语句子也来 ...