This shows you the differences between two versions of the page.
pt:global [2016/01/01 22:47] |
pt:global [2020/02/28 10:46] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Global ===== | ||
+ | ==== Formato ==== | ||
+ | **global** //variable list//\\ | ||
+ | |||
+ | ==== Descrição ==== | ||
+ | |||
+ | Global definirá uma lista de uma ou mais (separadas por vírgula) variáveis que podem ser acedidas e modificadas dentro [[subroutine|Subroutine]]s e [[Function|Function]]s. Estas variaveis globais podem ser também arrays. | ||
+ | |||
+ | Variaveis globais têm que ser definidas fora de qualquer bloco e antes de chamar a [[Function|Function]] ou [[subroutine|Subroutine]]. | ||
+ | |||
+ | ==== Exemplo ==== | ||
+ | |||
+ | < | ||
+ | global a, name$ | ||
+ | dim a(10) | ||
+ | dim name$(10) | ||
+ | a = {1, | ||
+ | name$ = {" | ||
+ | t = 99 | ||
+ | call printnames() | ||
+ | print t + " was unchanged - not global" | ||
+ | end | ||
+ | |||
+ | subroutine printnames() | ||
+ | for t = 0 to name$[?] -1 | ||
+ | print a[t] + " " + name$[t] | ||
+ | next t | ||
+ | end subroutine | ||
+ | </ | ||
+ | produz\\ | ||
+ | < | ||
+ | 1 Bob | ||
+ | 4 Sue | ||
+ | 6 Sam | ||
+ | 8 Jim | ||
+ | 45 Luis | ||
+ | 34 Guido | ||
+ | 76 Steve | ||
+ | 98 Angela | ||
+ | 43 Joe | ||
+ | 12 Paul | ||
+ | 99 was unchanged - not global | ||
+ | </ | ||
+ | ==== Ver também ==== | ||
+ | [[call|Call]], | ||
+ | |||
+ | ==== Introduzido ==== | ||
+ | 0.9.9.1 |