Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Code 04 - Table Intro
- -- Can be copied into Codea
- -- Bruce Elliott
- -- April 2013
- -- Use this function to perform your initial setup
- function setup()
- -- Create a table named kTab the name is not important
- -- use a name that helps document your code
- --
- -- in Codea each table entry consists of two parts.
- -- Here the first part are the numbers 1 to 15.
- --
- -- The second part of each entry is text. Here a single character.
- kTab={}
- kTab[1] = "1"
- kTab[2] = "2"
- kTab[3] = "3"
- kTab[4] = "4"
- kTab[5] = "5"
- kTab[6] = "6"
- kTab[7] = "7"
- kTab[8] = "8"
- kTab[9] = "9"
- kTab[10] = "0"
- kTab[11] = "+"
- kTab[12] = "-"
- kTab[13] = "*"
- kTab[14] = "/"
- kTab[15] = "="
- -- Display the table entries
- -- A for loop steps through a sequence of values
- --
- -- We are using pairs to access the table keys and values
- -- for each key (k) we want to get its value (v)
- -- We have to tell pairs which table to process
- --
- -- We display each key followed by its value
- -- Note: .. is used to concatenate (attach)
- -- parts of the output string
- for k, v in pairs(kTab) do
- print(k.." "..v)
- end
- -- Here we use print to display the value
- -- with key 12.
- print("val: "..kTab[12])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement