This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
dcleondc's profile picture

i need help with while statements

Started by dcleondc, 01 August 2012 - 03:13 AM
dcleondc #1
Posted 01 August 2012 - 05:13 AM
i need to compare a block its above with a block it has selected and if its true i need it to run one code and if its false i need it to run a different code.
here is the code i have that doesn't work.

function done()
    turtle.select(16)
    while turtle.compareDown() do
	    farm()
    else
	    skip()
    end
end
the function is part of a farming program im making.
Luanub #2
Posted 01 August 2012 - 05:16 AM
Hey man it's been awhile. while statements do not contain else functions, you will need to add in if into it. Try doing something like


function done()
    turtle.select(16)
    while turtle.compareDown() do
    if turtle.compareDown() then
            farm()
    else
            skip()
    end
    end
end
Xfel #3
Posted 01 August 2012 - 06:33 AM
You are aware of the fact that the else statement will never get called? I rather think he should replace the while with an if in his first code.