2 Selecting via the Arrow Keys
The four basic arrow keys on a standard keyboard can be used to adjust the current selection, in case you want to depart from the usual execution order.
Note that the current version of N-Dolphin has a few limitations, so some uses of arrow keys can cause the Python code to be replaced by an error message. As discussed in Section Display Bugs below, normally hitting up one or more times can remedy this problem (after that, trying Step in is often useful, or ask your instructor for help).
2.1 Basic code selection
The arrow keys control the selection as follows:
| up |
| select the expression that contains the current selection | |
| down |
| select the first expression within the current selection | |
| left |
| select the expression before current selection, within the same larger structure | |
| right |
| select the expression after the current selection, in the same larger structure |
For example, suppose we start with the code (3+4)*(28-8) already selected, perhaps just by hitting Step in to get there within a larger example, or because it’s the entire program. Hitting the down key would select the 3+4, and hitting down again would select 3; at this point, with the 3 selected, hitting up would go back to 3+4, whereas right would take us to the 4. With the 4 selected, left would take us back to the 3, up would take us to the 3+4, but right does nothing, since there’s nothing after the 4 within that 3+4, and down does nothing, because there’s nothing within the 4.
2.2 Order of execution vs. order in text, e.g., for if
The actions of the arrow keys are defined in terms of the order of parts of the expression, e.g., down taking you to the first sub-expression, and right taking you to the next. This order refers to the usual execution order, not the order you see things on the screen. Those are usually the same, but not always: Python’s if expression, like the if statement, normally runs the middle expression, i.e., the condition to be tested, before running either the true or false option based on that condition.
(9*8) if (4>5) else (6*12) |
if (4>5): |
return (9*8) |
else: |
return (6*12) |
For both of the above codes, the 4>5 is considered the first part, so down would select 4>5 if the entire code were selected, and you would need right to get from the 4>5 to the 9*8 in both forms; from the 9*8, right gets to the 6*12, and left to get from the 4>5.
2.3 Display Bugs
The current implementation of N-Dolphin has trouble displaying some specific sub-parts of some code, e.g., when trying to show only a variable initialization, without the subsequent code that uses the variable. Sometimes clicking arrow keys will cause N-Dolphin to select that un-displayable element, and then produce an error message about "selectionsplit needs update" where the python code would usually be displayed. In this case, try hitting up to select the entire code, and then Step in to let N-Dolphin pick the next part to show you.