Instead of making lots of nested if statements, use the if statements as an interruption check. This reduces the indentation a lot and makes it easier to read in my opinion. It also makes it easier to add stuff to these checks.
Also in the resulting g-code. Contributes to issue CURA-4615.
CURA-4615