Local variables are just that, their scope is limited to where they were declared. The main reason to use them is to not clutter the global namespace. There also exists static local variables, their scope are also limited to their declaration block but they don't get reinitialised to their default value.
As for using a function instead, I would probably have gone that way too. But Toddler did not want to clutter his function namespace with a function that he probably only use for one particular context. So I provided an alternative !