Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8479
  • 博文数量: 7
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-27 22:31
个人简介

风过竹林~那种感觉很神奇

文章分类

全部博文(7)

文章存档

2015年(3)

2014年(4)

我的朋友
最近访客

分类: C/C++

2014-12-30 20:39:51


点击(此处)折叠或打开

  1. --Example 13
  2. --More Output
  3. --io.write writes to stdout but without new line

  4. io.write("Hello from Lua!")
  5. io.write("Hello from Lua!")

  6. --Use an empty print to write a single new line
  7. print()


  8. -----------------Output---------------
  9. Hello for Lua!Hello for

  10. --Example 14
  11. --Tables
  12. --Simple table creation

  13. a = {} --{} creates an empty table
  14. b = {1, 2, 3} --create a new table containing numbers 1, 2, 3
  15. c = {"a", "b", "c"} --creates a table containing strings a, b, c
  16. print(a, b, c) --print do not print directly, we all get back to this


  17. -----------------Output----------------
  18. table: 004106A0 table: 00412340 table: 00411466


  19. --Example 15
  20. --More tables
  21. --Associate index style

  22. address = {} --empty address
  23. address.street = "X"
  24. address.streetNumber = 360
  25. address.AptNumber = "2a"
  26. address.City = "M"
  27. address.state = "N"
  28. address.country = "S"
  29. print(address.streetNumber, address["AptNumber"])


  30. ------------------Output-----------------

  31. 360 2a

  32. --Example 16
  33. --if statement
  34. --Simple if
  35. a = 1
  36. if a == 1 then
  37.     print("a is one")
  38.     
  39.     
  40. -----------------Output------------------

  41. a is one


  42. --Example 17
  43. --if else statement

  44. b = "happy"
  45. if b == "sad" then
  46.     print("b is sad")
  47. else
  48.     print("b is happy")
  49. end

  50. ------------------Output------------------

  51. b is happy

  52. --Example 18
  53. --if elseif else statement
  54. c = 3
  55. if c == 1 then
  56.     print("c is one")
  57. elseif c == 2 then
  58.     print("c is two")
  59. else
  60.     print("c isnot one and c isnot two , c is three")
  61. end

  62. ------------------Output--------------------

  63. c isnot one and c isnot two, c is three

  64. --Example 19
  65. --Conditional assignment
  66. -- value = test and x or y

  67. a = 1
  68. b = (a == 1) and "one" or "not one"
  69. print(b)

  70. -- is equivant to

  71. a = 1
  72. if a == 1 then
  73.     b = "one"
  74. else
  75.     b = "not one"
  76. end
  77. print(b)


  78. ---------------------Output--------------------

  79. one
  80. one


  81. --Example 20
  82. --While statement
  83. a = 1
  84. while a ~= 5 do
  85.     a = a+1
  86.     io.write(a.. " ")
  87. end


  88. ----------------------Output---------------------

  89.  2 3 4 5

阅读(179) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~