Find missing value in table or array

Hello,

Is there a way to iterate through a table or array and find missing value in it?
say i have t = {1,1,1,1,1}
and then in some point i remove one of those values and set it to 0

how can i find missing value? and then in some function set this 0 to 1

i read about it in some documents, but cant find it anywhere

any help is appreciated

easy

1
2
3
4
5
6
7
local i
 
t={1,1,1,0,1}
 
for i=1,#t do
 if t[i] == 0 then t[i]=1 end
end

wow, pretty cool, thanks for answer)

and a little question: what if there is not one but 2,3,4 zeroes in array, how can i set only the first found zero to 1?

darkconsoles: just call 'break' once you have found it ... that will exit the for loop :-)

thanks for help, i really appreciate it
if you dont mind, here is another question:

say i have this table "t = {0,0}"
and i have two objects on screen and i need to touch them and they appear on another side of screen based on a value in table
in example, if t = {0,0} it will move in x = 50, and if t = {1,0} it will move in x = 100, and if t = {0,1} it will move to x=50

hope it make any sense) how can i do this? i dont think stacking all those "if" will do any good, there is gotta be another way

so If I get this right,

0,0 = 50
1,0 = 100
0,1 = 50
1,1 = 100

so the second value means nothing in your example, it is the first value that is important.

Secondly, if you are trying to work with just these two values, you need to use simple Algebra

t = x + y
y = t - x

so, you need to use that way if you do not want to use "if"

try this, without using if statements,

local initial = 1

print( x ) --> should print 2 if Initial == 1 and 1 if initial is 2

BTW, this should not take more than a minute ;)

cheers,

?:)

views:1802 update:2011/10/19 8:59:29
corona forums © 2003-2011