lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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")
> num=io.read("*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",
"buscalLinear" instead of "linearSearch").  

  -spc