Set For Loop Target Property

LW Python pops the first element from the iterable and sets it to the target before entering the "for" body. More formally,

if the following are true:
  • the line at time t = i
  • the tab at time t = j
  • statement at line i, tab j = for target in iterable_ex:
  • value at j in map (Control Map at time t) = trio ("for", i, [ elem, rest ])

then Variables Map at time (t + 1) = result of storing elem at key: target in map: (Variables Map at time t)

For example, if the following are true:
  • the line at time 17 = 2
  • the tab at time 17 = 0
  • statement at line 2, tab 0 = for value in numbers:
  • value at 0 in map (Control Map at time 17) = trio ("for", 2, [ 1, [ 2, [ 3, [ ] ] ] ])

then Variables Map at time (17 + 1) = result of storing 1 at key: value in map: (Variables Map at time 17)

Try stepping through the simulator to see LW Python create a new variable "x"

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments