When developing algorithms, it might help to formulate an invariant first and then use it to guide all other steps.
This is the standard practice in formal program derivation.
// w > 0
x := 17;
// w > 0 and x = 17
y := 42;
// w > 0 and x = 17 and y = 42
z := w + x + y
// w > 0 and x = 17 and y = 42 and z > 59
// w + 17 + 42 < 0
x := 17;
// w + x + 42 < 0
y := 42;
// w + x + y < 0
z := w + x + y
// z < 0
In this course, we won't study the topic of formal semantics in detail.
This is done, for example, in the MSc course Programming Languages.