Lua中关系运算符的使用教程(关系运算符和逻辑运算符的区别)真没想到

随心笔谈2年前发布 admin
197 0 0

文章摘要

这篇文章展示了在编程中使用条件语句来判断变量值关系并执行不同操作的过程。代码中通过`if`语句依次判断变量`a`和`b`的相等性、不等性、大小关系等,并根据判断结果打印相应的信息。文章详细说明了变量赋值和条件判断的基本流程,突出了条件判断在程序控制中的核心作用。

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

© 版权声明

相关文章