Changing variables in a loop

Right! The combination of lexical scoping, expression return values, resulting in do/end variables being local and needing to assign out of them, is what’s the useful take-away.

I think if is great lesson in this, because

  • newcomers will often reach for it early
  • trying to re-assign something out of scope (which is commonly possible in other lexically scoped languages; that’s kind of what I meant by “functional” lexical scoping)
  • possibly discover after the assigning-result refactor that if they want the fallback case to be non-null, they also can return out of else
  • which sets them up for success when the conditional branching becomes more comples and they needbti reach for case; they will have acquired the understanding they need to succeed