0


I have table: {1,2,3,4,5,7,9} How to know that 5 is in this table? (for example)

flag offensive
asked 2010-08-24 10:44:21.274613
1
add comment
1 Answers:
0


Easy in python:

if 5 in {1,2,3,4,5,7,9}:
      print("Yay python!")

In lua, I wrote my own function:


function is_in_table(t,value)
    for i=1,#t do
        if t[i]==value then
            return true
        end
    end
    return false
end


a = {1,3,7,2,9}

if is_in_table(a,5) then
    print("5 is table a")
else
    print("not!")
end
permanent link | flag offensive
answered 2010-08-25 18:02:48.324190
46
add comment
Your answer:
You are now not logged in but you can answer first and then login
toggle preview



Tags:

× 3

Asked: 1 year, 8 months ago

Seen: 1,031 times

Last updated: 1 year, 8 months ago

Made with Django.