While Test Is False Property

If there is a "while" statement at the current line and tab and the "while" test evaluated to False at time t, then at time t + 1, the tab number remains the same. 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 = "while" statement with condition (function call with name: name and arguments: args)
  • Expression Stack at time t = [ [ ], [ ] ]
  • Value Stack at time t = [ [ False, [ ] ], [ ] ]

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

When the "while" statement test is False, Python skips the "while" statement body. This is done by incrementing the line number but keeping the tab number the same.

For example, if the following are true:

  • the line at time 34 = 2
  • the tab at time 34 = 0
  • statement at line 2, tab 0 = while a < 2:
  • Expression Stack at time 34 = [ [ ], [ ] ]
  • Value Stack at time 34 = [ [ False, [ ] ], [ ] ]

then the tab at time (34 + 1) = 0

Try stepping through the simulator. Initially, the condition "a < 2" is True, so the tab goes from 0 to 1. But in each iteration, the value of "a" increments by 1. When "a" is 2, the condition "a < 2" is False, and the "Current Tab" will remain at 0, and line 3 will be skipped.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments