[Top] - [Next] - [Previous]

The Three Main Execution Options

  1. Execution Mode
  2. Execution Speed
  3. Display Mode
  4. Starting Execution

Now that you know how Karel's world is displayed on your screen, it is time to focus your attention on the simulator's message line (the one at the top of the screen). Before the simulator can execute your program, there are three Execution Options that it must request: Execution Mode, Execution Speed, and Display Mode. This chapter discusses the possible choices for each of these options.

Execution Mode

The simulator first asks you to supply the Execution Mode you want. This request appears as:

     Enter Execution Mode([A]utomatic, [M]onitor, or [E]xplain)[M]:_

The following discussion contains a brief explanation of each of the possible Execution Mode answers.

In Automatic Execution Mode, the simulator automatically executes your program from start to finish, without any possible intervention from you. Think of this mode as the normal way that Karel executes our programs. In Automatic Execution Mode, the simulator continues executing your program until Karel executes a turnoff instruction or is forced to perform an error shutoff.
In Monitor Execution Mode, the simulator continually waits for you to OK the execution of the next instruction in Karel's program. By pressing the return key, you can direct Karel to execute one more instruction; the simulator then asks you again if it is OK for Karel to execute the new next instruction. When executing in Monitor Execution Mode, you can also change Karel's speed, make him go backwards in the program (unexecute some instructions), or make him execute large bunches of instructions either forward or backward. We shall continue our discussion of the details of Monitor Execution Mode in Chapters 6 and 8.
In Explain Execution Mode, the simulator uses the Explain line (fourth from the top on your screen) to explain, in great detail, how Karel is executing your program. In this mode the simulator tells you when Karel starts to execute defined instructions; when he starts BEGIN/END blocks;when he starts primitive, IF, ITERATE, and WHILE instructions; when he performs tests, what the outcome of each test is, etc. If you are unsure about exactly how Karel is executing your program, run the simulator in Explain Execution Mode for a very lengthy and detailed description.

Notice that in the above request for Execution Mode, Monitor Execution Mode is the default mode. This default mode was chosen because there are special commands in Monitor Mode that easily allow you to enter either Automatic or Explain Mode (and return to Monitor Mode from Explain Mode). Initially, run the simulator in Automatic Mode to reduce the amount of new material that you must learn. Before you try using Monitor Mode, read the chapter on Simple Stepping in Monitor Mode (Chapter 6).

Execution Speed

The second execution option that the simulator requests is Execution Speed. The following request appears on the message line at the top of your screen:

     Enter Execution Speed([F]ast, [M]edium, or [S]low)[F]:_

At the fast speed, Karel moves around the screen, but the simulator does not update its status line until Karel stops. At medium speed, each time Karel executes an instruction, the status line is automatically updated. This updating slows down the simulation by about a factor of 20 from its fast speed. Finally, at slow speed the simulator updates Karel's status and also prints a message after each instruction that Karel executes (the message tells which instruction he has just executed). Slow speed is about 5 times slower than medium speed, making it about 100 times slower than fast speed. The default speed is F, and this is a good speed to start with. If you find that the simulator is executing your program too quickly, you can re-run your program at a slower speed. Also, as mentioned before, if you are in Monitor Mode, you can easily change the simulator's speed. Finally, if you decide to choose Explain Mode, you will not have a choice of speeds: Explain Mode runs at only the slow speed.

Display Mode

The final execution option is Display Mode. The simulator's request for this option appears as:

     Enter Display Mode([R]egular or [S]ticky)[R]:_

In Regular Display Mode, whenever Karel moves off a corner, that corner's contents are redisplayed on the screen (that is, the number of beepers on that corner is redisplayed). In Sticky Display Mode, whenever Karel moves off a corner, his image remains stuck there. Running the simulator in Sticky Mode is useful for seeing the path that Karel takes, but it can be confusing, as you don't see the beepers on any corners where Karel has been. Also, if Karel repeatedly moves through a corner, only his last image through that corner would be displayed. Start with Regular Display Mode, the default answer. Again, if you are in Monitor Mode, you can easily change the Display Mode between Regular and Sticky.

Starting Execution

Finally, after you have entered all three of the necessary execution options, the simulator prints the following statement on your screen's message line:

     The simulator is ready to execute Karel's program.*

After you press the return key, the simulator will start executing your program in the initial situation, according to the options that you requested. f you are in Automatic Execution Mode, the simulator will continue executing your program until Karel executes a turnoff instruction or performs an error shutoff. If you are in Monitor or Explain Mode, you must keep stepping the simulator forward until Karel executes a turnoff instruction or performs an error shutoff. The next chapter discusses what you can do after the simulator has halted Karel's execution.

[Top] - [Next] - [Previous]