Return To For Statement Line Property

If LW Python reaches the end of the "for" loop body, then return to the "for" statement. 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 line at time (t + 1) = for_line

If the next statement's tab is less than the current tab number, then we know that the current block has ended. The "Control" map tells us that the "for" statement is in line 2. 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 line at time (26 + 1) = 2

Try stepping through the simulator to see LW Python move to line 4 and then return to line 2.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments