Return To For Statement Tab Property

If LW Python reaches the end of the "for" loop body, then return to the "for" statement by decrementing the tab number by 1 (among other things). More formally,

if the following are true:
  • the line at time t = i
  • the tab at time t = j
  • statement at line i, tab k = s
  • k < j
  • value at (j - 1) in map (Control Map at time t) = trio ("for", for_line, iterable)

then the tab at time (t + 1) = j - 1

If the next statement's tab is less than the current tab number, then we know that the current block has ended. For example, if the following are true:

  • the line at time 26 = 4
  • the tab at time 26 = 1
  • statement at line 4, tab 0 = for value in numbers:
  • value at (1 - 1) in map (Control Map at time 26) = trio ("for", 2, [ 7, [ ] ])

then the tab at time (26 + 1) = 1 - 1

Try stepping through the simulator to see the tab number decrease to 0 (and the line number change to 2).

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments