[Top] - [Next] - [Previous]

Simple Stepping in Monitor Mode

  1. The Stepping Prompt
  2. Simple Stepping Command Examples
  3. Other Stepping Commands

In Monitor Mode, the simulator continually asks you what needs to be done to continue Karel's execution of your program. In response to this request, you can re-adjust Karel's Execution Speed, you can decide whether Karel should execute his program forward or backward, and you can tell the simulator how much of Karel's program to execute before coming back and requesting another stepping command.

You should note here that executing a program backward is a useful feature: Assume that you are executing a program forward a bit at a time and suddenly find that something has gone wrong: the program did not do what you expected it to do. You can quickly execute the program backward a few steps, getting Karel back to a correct position, and then you can slowly execute the program forward until you find which instruction(s) caused the error.

The Stepping Prompt

When stepping forward in Monitor Mode, you will be presented with the following prompt line on the top of your screen:

     Ready To Step FORWARD(type ? for help)[F+1]:

In Monitor Mode, each step command consists of three parts (their order is important):

The Execution Speed: You can change the execution speed to fast, medium, or slow. In this example the default speed is fast, but by typing an M or S, you can alter the execution speed. In general, the default speed is always the speed that you typed the previous time that you were prompted with a Monitor Mode stepping request.
The Execution Direction: You can change the execution direction to either forward or backward. Here the default direction is +, which means that the program is being executed forward, the normal direction. By typing a -, you can make the simulator execute the program backward. Again, the default direction for this request is always the direction that you typed the previous time that the simulator prompted you with this line.
The Execution Step Size: The final part of the step command is a number that tells the simulator how many instructions to execute before re-requesting another stepping command. This number is always defaulted to 1. If you do enter a number, the simulator would step through that many instructions. You may also type a B, E, or Q, instead of a number. The B means execute backwards to the Beginning of the program (at the current speed); the E means execut forward to the End of the program (again, at the current speed); the Q means Quit execution and prompt for the Post-Execution Options (it sometimes first executes forward a bit before quitting).

Any parts of the step command may be omitted, but the remaining parts must appear in the order shown above. Given all these default values, if the user just presses the return key, the program is executed 1 step in the default direction at the default speed. Defaulting all the options and just pressing the return key is the most frequently used stepping command. Also, if only a speed or direction change is supplied, the default values are changed, but Karel does not execute (or unexecute) any instructions. To see a complete list of all the Monitor Mode command options, type a ? to the Monitor Mode prompt line (also, see Appendix I.1).

Simple Stepping Command Examples

The following list contains examples and explanations of simple Monitor Mode stepping commands.

F+5        Change to fast speed and execute in the forward direction 5
M-         Change to medium speed and backward execution, but do not actually
           unexecute any instructions yet.
-15        At the current speed, execute backward (unexecute) 15 instructions.

The next three examples indicate how the letters B, E, and Q are used in Monitor Mode commands. Remember, a B means step to the beginning, and E means step to the end, and a Q means quit.

FB         Execute the program at a fast speed backward until it reaches the
           beginning of its execution (the initial situation).
E          Execute the program at the current default speed forward until it
           reaches the  end of its execution (the final situation).
Q          Quit execution of the program, then prompt the user for Post-
           Execution Options.

The second example is equivalent to executing the program in Automatic Mode at the current default speed. In all three cases, you cannot alter Karel's behavior until after the simulator finishes executing Karel's program.

Other Stepping Commands

The P command allows you to Print on your screen the definition of any defined instruction in Karel's program. You can specify which instruction to print by typing its name, or you can use the default instruction name, in which casethe simulator prints the defined instruction in which Karel is currently executing. If you do request the currently executing definition, a * will be printed next to the line number of the currently executing instruction within that definition. Before it returns to the Monitor Mode prompt, the simulator allows you to print as many instruction definitions as you want.

The D command Displays the list of all defined instructions in which Karel is currently executing. This list always starts with BEGINNING-OF-EXECUTION, and it grows downward until it reaches the currently executing defined instruction. The line number of the current execution point in each of these define instructions is printed along with the instruction's name.

The L command, also seen as a Post-Execution Option, allows you to Look at various portions of Karel's world that are not currently displayed on your screen.

The O command allows you to change your three Execution Options (Execution Mode, Execution Speed, and Display Mode). Thus, from Monitor Mode you can easily switch to Automatic Mode or Explain Mode.

The P, D, L, O, and R commands (R redraws the screen) also work in Explain Mode (see Appendix I.2). By using the O command, you can easily switch between Monitor Mode and Explain Mode.

[Top] - [Next] - [Previous]