Advertisement
br1wr2el3

Code 04 - Array Intro

Apr 19th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. -- Code 04 - Table Intro
  2. -- Can be copied into Codea
  3. -- Bruce Elliott
  4. -- April 2013
  5.  
  6. -- Use this function to perform your initial setup
  7.  
  8. function setup()
  9. -- Create a table named kTab the name is not important
  10. -- use a name that helps document your code
  11. --
  12. -- in Codea each table entry consists of two parts.
  13. -- Here the first part are the numbers 1 to 15.
  14. --
  15. -- The second part of each entry is text. Here a single character.
  16.  
  17. kTab={}
  18. kTab[1] = "1"
  19. kTab[2] = "2"
  20. kTab[3] = "3"
  21. kTab[4] = "4"
  22. kTab[5] = "5"
  23. kTab[6] = "6"
  24. kTab[7] = "7"
  25. kTab[8] = "8"
  26. kTab[9] = "9"
  27. kTab[10] = "0"
  28. kTab[11] = "+"
  29. kTab[12] = "-"
  30. kTab[13] = "*"
  31. kTab[14] = "/"
  32. kTab[15] = "="
  33.  
  34. -- Display the table entries
  35. -- A for loop steps through a sequence of values
  36. --
  37. -- We are using pairs to access the table keys and values
  38. -- for each key (k) we want to get its value (v)
  39. -- We have to tell pairs which table to process
  40. --
  41. -- We display each key followed by its value
  42. -- Note: .. is used to concatenate (attach)
  43. -- parts of the output string
  44.  
  45. for k, v in pairs(kTab) do
  46. print(k.." "..v)
  47. end
  48.  
  49. -- Here we use print to display the value
  50. -- with key 12.
  51.  
  52. print("val: "..kTab[12])
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement