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

Need help with a while loop

Started by badkruka, 24 January 2014 - 05:46 AM
badkruka #1
Posted 24 January 2014 - 06:46 AM
Hello!
I have a problem with a while loop. I want the program to be stuck at that loop untill it get the message "fardiga" from computer with channel 1.
As I have programmed it now it breaks the loop as soon anything is sent to the computer. I know how and works but not when I start adding not condition to it.
Can anyone help with the right conditons and why this loop seems to let everything throu it.


function getInfo()
   _, side, freq, rfreq, message = os.pullEvent("modem_message")
end

getInfo()
while rfreq ~= 1 and message ~= "fardiga" do
   getInfo()
end
Lyqyd #2
Posted 24 January 2014 - 10:23 AM
You want an or instead of an and; "while either one of these conditions are not met, continue to loop".
Isitar #3
Posted 24 January 2014 - 11:59 AM
Hello!
I have a problem with a while loop. I want the program to be stuck at that loop untill it get the message "fardiga" from computer with channel 1.
As I have programmed it now it breaks the loop as soon anything is sent to the computer. I know how and works but not when I start adding not condition to it.
Can anyone help with the right conditons and why this loop seems to let everything throu it.


function getInfo()
   _, side, freq, rfreq, message = os.pullEvent("modem_message")
end

getInfo()
while rfreq ~= 1 and message ~= "fardiga" do
   getInfo()
end

Hi

Here's your code

function getInfo()
   _, side, freq, rfreq, message = os.pullEvent("modem_message")
end
getInfo()
while (rfreq ~= 1) or (message ~= "fardiga") do
   getInfo()
end
badkruka #4
Posted 24 January 2014 - 12:30 PM
Thanks alot.