Before we get to the code, we need to explain the very important concept/tool called a loop.
A loop is a piece of code that repeats until some stopping condition. We’ll go into the how the stopping condition works in the next project, for now let’s go over a loop that doesn’t stop, the forever/infinite loop.
Shown here is an example of a forever loop. We have the word while and the word True surrounded by “()”ending with a “:”. If any of these things are missing the loop won’t work, be sure to have all of them.
We also have some more code that has an indent (done by pushing “tab” on the keyboard). Only code that is indented is part of the loop, if it isn’t indented it is not in the loop.
In this example, we have one line of code that will be repeated. In this program, the computer will repeatedly print out the word “Hi!” on our screen.
Feel free to test this out yourself; however, if you have the code from the previous page, you will need to have a Minecraft world open for it to work. To force stop an infinite loop, press Ctrl+C in the terminal.