Hierarchy and Overwriting

Misconception 1

Misconception: The following printed code will return a y value of 20.

Hierarchy and Overwriting Misconception 1 - 1.png
Actual return: Hierarchy and Overwriting Misconception 1 - 2.png
Explanations:

Because of the hierarchy in the procedures, information in the codes are transferred downstream. The value of y is in the 2nd line of code will only depend on the value of x from 1st line.

Hierarchy and Overwriting Misconception 1 - 3.png
Even though the value of x in the 3rd line of code will overwrite the value of x in the first line. It will not transfer the information upstream or update the value of y in the previous line.

Hierarchy and Overwriting Misconception 1 - 4.png
Correct workflow: Create new definitions.

Hierarchy and Overwriting Misconception 1 - 5.png
Return: Hierarchy and Overwriting Misconception 1 - 6.png


Misconception 2

Misconception: The y value inside the loop will not overwrite the y value upstream and outside of the loop, hence check_y will return a value of 10.

Hierarchy and Overwriting Misconception 2 - 1.png
Actual returns: Hierarchy and Overwriting Misconception 2 - 2.png
Explanations:

The y value upstream and outside of the For loop is overwritten by the y value downstream in the For loop.

Although the For loop operates rather independently in the sense that the variables defined inside of a For loop cannot be referenced out of it unless they are added into an external list. However, the terms upstream outside of the For loop can be referenced and overwritten inside the loop.

Correct Workflow: Use differently named terms from upstream in the For loop when the terms are not meant to overwrite the previous terms.

Hierarchy and Overwriting Misconception 2 - 3.png
Return: Hierarchy and Overwriting Misconception 2 - 4.png

results matching ""

    No results matching ""