Exercise 2.2 – converting loops
In this exercise, we will convert a functioning while
loop into a repeat
loop. Both loops are very similar. In the Programming loops section, we explained the difference between both. Take a look at the following code snippet:
local spawnLocation = workspace.SpawnLocation while true do spawnLocation.Orientation += Vector3.new(0, 1, 0) task.wait() end
This code snippet rotates SpawnLocation in the Workspace. Feel free to run this script before you convert it.
Exercise:
- Convert the preceding code snippet into a
repeat
loop. - What is different about the condition of the
repeat
loop compared to thewhile
loop, and why?
Play the game and make sure the spawn location rotates. If the Output frame displays any errors, try to fix them. An example answer to this exercise can be found on the GitHub page for this book:
https://github.com/PacktPublishing/Mastering-Roblox-Coding/tree/main/Exercises
...