欢迎来到山村网

Lua中关系运算符的使用教程

2019-03-02 13:33:40浏览:272 来源:山村网   
核心摘要:  这篇文章主要介绍了Lua中关系运算符的使用教程,是Lua学习入门中的基础知识,需要的朋友可以参考下  下表列出了所有的Lua语

  这篇文章主要介绍了Lua中关系运算符的使用教程,是Lua学习入门中的基础知识,需要的朋友可以参考下

  下表列出了所有的Lua语言支持的关系运算符。假设变量A持有10和变量B持有20则:

201552893006602.jpg (626×426)

  示例

  试试下面的例子就明白了所有的Lua编程语言提供的关系运算符:

  代码如下:

  a = 21

  b = 10

  if( a == b )

  then

  print("Line 1 - a is equal to b" )

  else

  print("Line 1 - a is not equal to b" )

  end

  if( a ~= b )

  then

  print("Line 2 - a is not equal to b" )

  else

  print("Line 2 - a is equal to b" )

  end

  if ( a < b )

  then

  print("Line 3 - a is less than b" )

  else

  print("Line 3 - a is not less than b" )

  end

  if ( a > b )

  then

  print("Line 4 - a is greater than b" )

  else

  print("Line 5 - a is not greater than b" )

  end

  -- Lets change value of a and b

  a = 5

  b = 20

  if ( a <= b )

  then

  print("Line 5 - a is either less than or equal to b" )

  end

  if ( b >= a )

  then

  print("Line 6 - b is either greater than or equal to b" )

  end

  当建立并执行上面的程序它会产生以下结果:

  代码如下:

  Line 1 - a is not equal to b

  Line 2 - a is not equal to b

  Line 3 - a is not less than b

  Line 4 - a is greater than b

  Line 5 - a is either less than or equal to b

  Line 6 - b is either greater than or equal to b

(责任编辑:豆豆)
下一篇:

Lua中的逻辑运算符使用详解

上一篇:

Python fileinput模块使用实例

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com