Extract data out of a Loop Using Lists

Variables within a loop cannot be directly referenced outside of loop. As such, users have to create lists to extract values from the last iteration or each iteration of a loop.

Error Notification Upon Directly Referencing a Variable Within a Loop Outside of the Loop
Figure: Error Notification Upon Directly Referencing a Variable Within a Loop Outside of the Loop


Extracting Values of the Last Iteration

To extract the last iteration of a For/While loop i.e. total_apple, create an empty list of the same variable name i.e. total_apple = [], outside and upstream of the loop. Placing the same variable name downstream and out of the loop will successfully acquire the last iteration of the loop.

Extracting Values of the Last Iteration From a For Loop
Figure: Extracting Values of the Last Iteration From a For Loop
Extracting Values of the Last Iteration From a While Loop
Figure: Extracting Values of the Last Iteration From a While Loop


Extracting Values From Each Iteration

To extract the value of total_apple from each iteration of a For/While loop, create an empty list upstream and outside of the loop and insert the function list.Add into the loop. This will add the value of total_apple in each iteration into the upstream list.

Extracting Values From Each Iteration in a While Loop
Figure: Extracting Values From Each Iteration in a While Loop

results matching ""

    No results matching ""