• Subject: Re: What wrong in this code?
• From: Jorge Eduardo de Araújo Oliveira <jorgeeduardoaoliveira@...>
• Date: Mon, 15 May 2017 05:10:13 -0300

Wow!
I'm sorry...
The right code is it:

function linearSearch(table,element)
local position=0
while position<#table do
if table[position]==element then
return position
else
position=position+1
end
end
end
math.randomseed(os.time())
array={}
for i=1,10 do
array[i]=math.random(0,99)
end
print(table.concat(array,","))
io.write("Enter a number to search in array:\n")
linearSearch(array,num)

Em 15 de mai de 2017 04:59, "Sean Conner" <sean@conman.org> escreveu:
It was thus said that the Great Jorge Eduardo de Araújo Oliveira once stated:
> I was writing a code to do linear search:
> What wrong?
>
> function linearSearch(table, element)
> local position=0
> while position<#table do
> if table[position]==element then
> return position
> else
> position=position+1
> end
> end
> end
> math.randomseed(is.time())
> array={}
> for i=1,10 do
> array[i]=math.random(0,99)
> end
> print(table.concat(vetor,","))
> io.write("Enter a number to search in  array:\n")
> buscaLinear(array,num)

Problem 1: lua-53: y.lua:11: attempt to index a nil value (global 'is')
stack traceback:
y.lua:11: in main chunk
[C]: in ?

Problem 2: lua-53: y.lua:16: bad argument #1 to 'concat' (table expected, got nil)
stack traceback:
[C]: in function 'table.concat'
y.lua:16: in main chunk
[C]: in ?

Problem 3: lua-53: y.lua:22: attempt to call a nil value (global 'buscaLinear')
stack traceback:
y.lua:22: in main chunk
[C]: in ?

Quite a few typos ("is" instead of "os", "vector" instead of "array",