Scope of variables inside functions, for loops, and if statments

Declaring something global makes it global, not local to the function. You can either use a let like @Vasily_Pisarev did or put local am, dt at the top of the function body to declare those variables in the outermost scope of the function instead of the loop body where they are assigned.

Please quote your code: Please read: make it easier to help you - #11

3 Likes