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

Repeat Loop Trouble

Started by flipsyo, 20 August 2012 - 07:47 AM
flipsyo #1
Posted 20 August 2012 - 09:47 AM
Hi all, spanking new programmer here, lots of fun so far and have made lots of progress.

im having an issue with creating a repeat loop for my farming turtle though, ive spent about 5 or 6 hours trying to figure it out but it is burning a hole in my brain. here is the loop i have made

————————————————————————————————

print("Breadurtle sings: Breeaaaadfannn, dunnuh dunnuh duuuuu…")
print("Breadurtle says: Bread?")

input = read()

if input == "yes" then
print("Breadurtle shouts: Breaaaaddd!")
startroute()
fsection()
fsection()
fsection()
fsection()

elseif input == "no" then
print("Breadurtle sniffles: Aw ok")

else
repeat
print("Chicken?")
input = read()
until input == "yes" or "no" – this part is not working
end

sleep(2)
term.clear()
term.setCursorPos(1,1)

————————————————————————————

when i dont type yes or no, it prints out "chicken?" and lets me input something. The second time i try to input something, the pc sleeps for 2 seconds and then clears out. Basically what im trying to do is, if i dont input yes or no, i want it to repeat the "chicken?" text until i DO input yes or no.

I may not even be using the correct loop haha, what would you guys suggest?

thanks in advance
sjele #2
Posted 20 August 2012 - 01:49 PM

print("Breadurtle sings: Breeaaaadfannn, dunnuh dunnuh duuuuu...")
print("Breadurtle says: Bread?")
input = read()
if input == "yes" then
print("Breadurtle shouts: Breaaaaddd!")
startroute()
fsection()
fsection()
fsection()
fsection()
elseif input == "no" then
print("Breadurtle sniffles: Aw ok")
else
input = "" --Just to have input preset. Idk if this is needed, We need this if not it would have just skipped it.
while input ~= "yes"  --Used a while instead of repeat loop
print("Chicken?")
input = read()
end					--End while
end					--End if(That you had premade in here
sleep(2)
term.clear()
term.setCursorPos(1,1)
Yes, was already yes, so it skipped the reapeat loop, I altred it to use a while loop as i did notice it before now :D/>/>
Cloudy #3
Posted 20 August 2012 - 04:17 PM
until input == "yes" or "no" will not be valid code. "no" will evaluate to true as it is not nil. What you should do is:

until input == "yes" or input == "no"
flipsyo #4
Posted 25 August 2012 - 09:31 PM
awesome thanks guys! you were great help, after taking some of your infos, messing around with things and waiting for the website to come back up, i came up with this: it works!!!

print("Breadurtle sings: Breeaaaadfannn, dunnuh dunnuh duuuuu…")
print("Breadurtle says: Bread?")

input = read()

repeat
print("Chicken?")
input = read()
until input == "yes" or input == "no"

if input == "yes" then
print("Breadurtle shouts: Breaaaaddd!")
startroute()
fsection()
fsection()
fsection()
fsection()

elseif input == "no" then
print("Breadurtle sniffles: Aw ok")

end
sleep(2)
term.clear()
term.setCursorPos(1,1)