Variables in While Loops

If I only want to run through a program once, and not have it infinitely repeat, can I leave it out of a while loop and still have the sensors in the program work?

Without a while loop, you can have the sensor work, but only for the amount of time that it reads one value. It all depends on the code you use. If you don’t have a while loop then the sensors will not update their values and therefore they would be un-usable.

However you can set the while loop to work for a specific amount of time and then exit the loop after a certain amount of time. This would allow you to control the duration of the loop so that it would not repeat infinitely.


Thank you. So without a while loop would it act like the way a touch sensor acts in lego robotics? What would I do to the loop to make it only go for a set amount of time?

Set the condition for the while loop to a timer.

You can use a timer. However, in my opinion, I think that a for loop would be more practical.


If you want to make a while loop that stops after a certain amount of time you could add a delay for how ever long you want the loop to go and then right after that put the program flow block called break loop and it will jump to the next loop.

I am not sure if this helps but if you need help just post and ask me, i would be glad to help.