0

Line Robot - Basic lessons - Program end

In the beginning, our whole program will be inside function loop(). It is not important that You grasp the term function just yet. You can only remember where Your program will sit, and that is here, where placeholder "//Write Your program here" is:
void RobotLine::loop() {
	//Write Your program here
}
Depending on version, this text may not exist or may be altered. Never mind, You will always write Your program between the 2 curly brackets. When You choose "loo" command in Your mobile or PC terminal, this program will start running. It is very important to note that it will not be run just once, but many times, repeating this function relentlessly, many thousands of times every second. As the command above starts with "//", nothing will be done, because "//" denotes start of the comment, a part of the program which is only for making notes, and does not produce any executing code.
Of course, there must be a way to stop it and there are indeed even 2 ways. First one is to hit "x" command in Your terminal. The second one is to enter command:
end();
somewhere in Your code. The effect will be exactly the same: the function will execute no more. The whole simple function is here:
void RobotLine::loop() {
	end();
}
You may not understand why there are "(", ")", and ";" signs here. It will be a common pattern in these lessons: we will not be explaining too much as we believe it is more important to present the concept clearly than precisely. Just a word about ";", though. This sign stands for "end of instruction". For example, this code will not work:
void RobotLine::loop() {
	end()
	end()
}
Do not pay attention what the purpose of this program is. end() after end() makes no sense, but that is not the point. Concentrate on ";" instead. For the computer, this program is equivalent to:
void RobotLine::loop() {
	end()end()}
The correct form is:
void RobotLine::loop() {
	end();
	end();
}

Task: stop the program

Look at the program above. How many times will the function be executed?