Using the table posted below I would like to find every dictionary key with a specific value ranging from 0 to 1 (A to D) and ignore the rest (E to H). Can anyone give me advice as to how I can approach this?
01 | ExampleTable = { |
02 | [ "A" ] = 0 , |
03 | [ "B" ] = 0 , |
04 | [ "C" ] = 1 , |
05 | [ "D" ] = 1 , |
06 | [ "E" ] = 2 , |
07 | [ "F" ] = 2 , |
08 | [ "G" ] = 3 , |
09 | [ "H" ] = 3 , |
10 | } |
With the example provided, something like this should work:
1 | for i,v in pairs (ExampleTable) do |
2 | if i = = "A" or i = = "B" or i = = "C" or i = = "D" then -- Checking if the key is A to D |
3 | print (v) -- Printing the value |
4 | end |
5 | end |