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.
  Counted Loop
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 header of the loop, which consists of a count of iterations and a loop icon.
     
  • The body of the loop, which consists of a command (or the block of commands), which you want to execute several times.
After inserting the command to the program a window appears close to the command icon. You can specify a number of iterations in the window. The number is added in front of the icon and together with the icon it represents the header of loop. If you want to change the number later, just click on it. For further information on a dialog for inserting a numeric value see the page Inserting numeric values.
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.
Example (For mode 3D)
Baltie goes five steps forward, conjures up a wrapped parcel, turns back (turns left two times) and goes 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.
Example (For mode 3D)
Baltie conjures up four times a table, a computer and a chair respectively, and then moves 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.
Example (For mode 3D)
Baltie goes five steps forward, conjures up a wrapped parcel, turns back (turns left two times) and goes back to its original position four times.
Was this helpful?
  Command blocks
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.
Example (For modes 2D, 3D)
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.
Example (For mode 3D)
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