Scope of global variables in Subroutine. (Release Announcements)

by aprekates, Wednesday, June 17, 2015, 09:32 (740 days ago)

T=1

CALL TEST()

SUBROUTINE TEST()
PRINT T
END SUBROUTINE


ERROR on line X: Unknown variable T.


Is that behavior correct? A subroutine cant see global vars.

Scope of global variables in Subroutine.

by aprekates, Wednesday, June 17, 2015, 09:45 (740 days ago) @ aprekates

OK. Solved.
I havent seen the GLOBAL keyword.

Scope of global variables in Subroutine.

by Jim ⌂ @, Russell, KY, Monday, October 26, 2015, 23:30 (608 days ago) @ aprekates

You are correct, In many languages c, javaScript, ... the variables defined outside of a function are available globally. This often leads to very sloppy code with lots of globals, in beginning programmers. The BASIC I learned kept each function/subroutine as a separate variable context (except for the ones specifically set as global). Old habits.

Jim

RSS Feed of thread
powered by my little forum