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的更多相关文章

  1. .Net基础篇_学习笔记_第五天_流程控制while循环

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. .Net基础篇_学习笔记_第四天_if结构

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. 循环结构——while、do-while、for循环

    1.while循环 语法格式: while(条件判断){ 循环体 } 解释: (1)关键字while后的小括号中的内容时循环条件. (2)循环条件是一个布尔表达式,它的值为布尔类型 "真&q ...

  4. .Net基础篇_学习笔记_第六天_for循环的几个练习

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. .Net基础篇_学习笔记_第六天_for循环的嵌套_乘法口诀表

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. .Net基础篇_学习笔记_第六天_for循环语法_正序输出和倒序输出

    for TAB  和 forr TAB using System; using System.Collections.Generic; using System.Linq; using System. ...

  7. .Net基础篇_学习笔记_第六天_For循环语法

    For循环:专门处理已知循环次数的循环.  小技巧:连续敲击两下TAB键循环体自动搭建完成. For循环语法: for(表达式1;表达式2;表达式3){ 循环体;}表达式1一般为声明循环变量,记录循环 ...

  8. .Net基础篇_学习笔记_第五天_流程控制do-while循环

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. .Net基础篇_学习笔记_第五天_流程控制while循环003

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

随机推荐

  1. [转]WCF的几种寄宿方式

    转自:WCF开发框架形成之旅---WCF的几种寄宿方式 WCF寄宿方式是一种非常灵活的操作,可以在IIS服务.Windows服务.Winform程序.控制台程序中进行寄宿,从而实现WCF服务的运行,为 ...

  2. open cursor too much error

    今天遇到一个错误ORA-01000: maximum open cursors exceeded. 客户想增加 DB 的open_cursor这个参数. 但是我看了下,她的程序要打开几千个cursor ...

  3. Navicat 提示Cannot create oci environment 解决方式

    一直在使用Navicat,这是一个数据库client软件.能连接多种不同类型的数据库,给我们的日常的工作带来了不少的便捷.近期.我在电脑上安装了orcale,然后,Navicat就莫名其妙的不能连接o ...

  4. StringIndexOutOfBoundsException

    <span style="font-family:Microsoft YaHei;font-size:14px;">public class StringIndexBo ...

  5. SharePoint 2013 关闭 customErrors

    在SharePoint 2013上做开发时,如果不把customErrors 关掉,那调试起来那真叫一个费劲.在2013里,关闭customErrors 和2010一样,只要把文件路径改成15目录下即 ...

  6. Python字符串转为字典方法大全

    方法一: 通过内置函数eval str_info = '{"name": "test", "age": 18}' dict_info = e ...

  7. hive-0.11.0安装方法具体解释

    先决条件:     1)java环境,须要安装java1.6以上版本号     2)hadoop环境,Hadoop-1.2.1的安装方法參考hadoop-1.2.1安装方法具体解释 本文採用的hado ...

  8. How to Integrate .NET Projects with Jenkins

    https://www.swtestacademy.com/jenkins-dotnet-integration/ 8) Unit Tests and Test Coverage Settings D ...

  9. C# 实现DataGridView分页功能

    C#实现DataGridView分页功能 2010-07-17 13:45:42|  分类: C#|字号 订阅     从界面可以看到,在设计时需要一个DataGridView.BindingNavi ...

  10. 【POJ 3074】 Sudoku

    [题目链接] http://poj.org/problem?id=3074 [算法] 将数独问题转化为精确覆盖问题,用Dancing Links求解 转化方法如下 : 我们知道,在一个数独中 : 1. ...