2018-08-01

lua中的分支结构


  • if 语句
    me = {gender = "boy", age = 18, stature = 182}
    if me.gender == "boy" and age == 18 then
    print("handsome boy!!")
    end

      -- 多分支
      if me.gender == "boy" then
          print("handsome boy!!")
      elseif me.gender == "girl" then
          print("big old! big old! ORZ!")
      else
          print("made me feel pins and needles! ORZ! ORZ!!")
      end
    
      -- 分支嵌套
      if me.gender == "boy" then
          print("handsome boy!!")
          if me.stature > 180 then
              print("so tall!!")
          end
      elseif me.gender == "girl" then
          print("big old! big old! ORZ!")
      else
          print("made me feel pins and needles! ORZ! ORZ!!")
      end
    

程序运行结果:


result.png
    if语句的语法:
    if [condition] then
        [your coder logic]
    end

转载请写明出处:https://www.jianshu.com/p/6551254c8364

你可能感兴趣的:(2018-08-01)