Nonlocal Quick Review

Local Variables = Variables that are defined in your current frame

Up until this point, we have only used local variables and variables from parent frames in our functions. However, we were only ever able to change the values of the local variables. What if we could change the values of variables from our parent frames?

Nonlocal Variables = Variables that are not defined in our current frame that we can change the values of

Two important rules

In order to declare a variable nonlocal in you current frame:

It must be defined in a parent frame (or a grandparent, great-grandparent etc. frame, if you will) of your current function that is not the global frame

It cannot share a name with a variable that is local to your current frame

a quick side note

When defining a nonlocal variable in an environment diagram, you do not write it in your current frame. I recommend marking it (maybe with a star) in whatever frame it came from, just to remind yourself that it is nonlocal, and so you may be changing its value from the frame that you are in.