Programming loops
Quite a few times, we have made systems without taking them to the fullest, primarily because we missed knowledge of loops. Loops allow us to repeat a process multiple times without having to copy and paste the same code over and over again. This section explains everything you need to know about loops.
Here is a list of the three different loops that Luau has:
In the following sections, we will dive deeper into each of these loops.
while loops
The first loop we will look into is the while
loop. As previously mentioned, a while
loop keeps repeating the same code until a condition is met. Let us take a look at the following code:
function randomBoolean() return math.random(0, 5) == 0 end function countTries() -- Counter variable local tries = 0 -- While Loop while randomBoolean() == false do tries += 1 end &...