Thursday, August 15, 2024

Geese sketches and coding tip

 







Coding tip: to avoid having a whole bunch of indented if statements. Instead could write a series of single indented if statements with the not condition and have it return above your code of interest. So if get to your line of code it’s known that all the conditions above were never met.
A simple example in pseudo code.
Instead of:
If a:
      If b:
            If c:
                  Print yay

Can write:
If not a:
    Return
If not b:
     Return
If not c:
     Return
Print yay

Happy Sketching!

Inspired by,
Glen Keane