Command blocks and loops are close related to each other because the body of most loops consists of a command block. On the other hand, the most common usage of the command blocks is with loops.
You can use the counted loop anytime you need some command (or block of commands) executed more than once. You must know how many times the command should be executed.
The loop statement consists of two parts:
The body of loop (a command or a group of commands, which should be executed several times) should be appended to the header of the loop.
In the next picture you can see a part of the program, which makes Baltie go five steps forward, conjure up a wrapped parcel, turn back (turn left two times) and go back to its original position.
If it is necessary to execute a group of commands, you must tie up these commands to the block of commands. The loop will execute the whole block after then. (Blocks of commands are discussed in depth in the next section.)
The next sample will let Baltie to conjure up four times a table, a computer and a chair respectively, and then move to the next cube where he can conjure up the next workplace.
The loops can be even nested. That means, the body of loop may contain another loop. The next sample will execute the previous placing-parcels program forty times, with Baltie's turn left anytime he returns to the initial position.
Was this helpful? ![]() ![]() ![]()
You will use A block of commands
anytime you need to assign several commands at the position where just one command is allowed. The program considers a command block as a single command.
When you are inserting a command block to the program, two icons are placed to the program which represent the left and the right brace bounding of the command block.
The most common reason to use a command block is the fact that you need to use several commands in program statements, which require just one command. By bounding the commands up to a group you can use them as a single command, acceptable for the statement.
Loops are a standard example of such a statement. If you need to execute a group of several commands repeatedly (in loop), tie up the commands to the group.
To clarify the concept you can see a part of the program in the following picture. The program contains a loop, which makes Baltie turn left and go forward two imaginary cubes four times.
If the command block occupies more than one line, it is a good idea to intend all lines inside the block, so the commands in the block begin at the position, which is moved one icon right than is the position of the line with the open brace.
The following sample shows the program, which forces Baltie to build a classroom with five rows of computer workplaces. Each row contains four workplaces.
You can use a command block even to increase a lucidity of the program.
Was this helpful? ![]() ![]() ![]() Did you find this information useful? ![]() ![]() ![]() Documentation of SGP Baltie 4 C# Send us comments on this topic by this form ©1978-2010 SGP Systems Parent page | Previous page | Next page |