The block program is executed one by one from the top to the bottom.
That means that when you get to the bottom, it's over.
This time I'm going to show you how to keep the program running without ending it.
What's good about moving all the time?
We use loops when we "wait" for something, for example, waiting for a button to be pressed, or for a human being to appear on the camera.
In other words, "I'm going to use a loop and check it over and over until it happens.
In addition to blocks that do something like "put the letters on the screen", there are blocks that determine the movement of the block. The "loop" is one of them.
A block in the "loop" can be a block within a block.
When you put it in, the block you put in will be executed from the top in the same way, but when you get to the bottom, it will go back to the top of the loop and be executed again.
Let's put a loop in the block where the text appears in the console after connecting to the previous obniz.
If you look inside the loop, there are several loops. This time, I'll use the one labeled "repeat do".
This is a block that repeats the block you put in it all the time.
I'm going to put this in after connecting it to obniz, and then I'm going to put something that displays text on the console in it.
This way, the text will stay on the screen the whole time.
And when you run it, you will see a lot of "Connected" characters on the program screen after it is connected to obniz as shown in the image below.
Now I've managed to keep it running all the way through the program without finishing it!
Types of loops
There are other blocks in the "loop" besides "repeat do. For example, this is a block that will loop a specified number of times; 10 will only be executed 10 times
This loop is a block that loops only when certain conditions are met.
And this is not a loop, but a block that only waits for a certain amount of time.
Looping is a very heavy burden on your smartphone or PC because you have to repeat it all the time.
Giving them time to do nothing and rest will prevent them from draining the battery.
If you're willing to wait, it's good for your battery if you put this block in a repetition.