After more messing around than this should have required, it turns out the answer is:
Although most statements are supported in the Immediate window, a control structure is valid only if it can be completely expressed on one line of code; use colons to separate the statements that make up the control structure. The following For loop is valid in the Immediate window:
For I = 1 To 20 : Print 2 * I : Next I
(which is formally documented here.)
Some additional details:
Variables in the immediate window do not require declaration -- even if Option Explicit
is used in the module / program being run. This makes arbitrary for-looping convenient (but also makes mistakes easier when trying to reference variables in current scope).
Printing can be done with any of: Debug.Print
, just Print
or ?
Nested loops work.