This shows you the differences between two versions of the page.
pt:ref [2016/01/01 22:48] |
pt:ref [2020/02/28 10:46] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Ref ===== | ||
+ | ==== Formato ==== | ||
+ | subroutine subroutinename ( // | ||
+ | call subroutinename ( // ref(variable), | ||
+ | \\ | ||
+ | function functionname ( // | ||
+ | functionname ( // | ||
+ | ==== Descrição ==== | ||
+ | |||
+ | Por norma os parâmetros são passados para as sub-rotinas e funções por valor. Isso significa que o valor especificado ao chamar a sub-rotina é totalmente local para esta. | ||
+ | REF() permite que se passe uma referência a uma variável ou um array para a rotina. Quando a rotina de alterar o valor da variável de referência, | ||
+ | ==== Exemplo ==== | ||
+ | |||
+ | < | ||
+ | dim a(5) | ||
+ | |||
+ | # atribui valores a cada elemento to array | ||
+ | for t = 0 to 4 | ||
+ | a[t]= int(rand*6) | ||
+ | print a[t] | ||
+ | next t | ||
+ | |||
+ | |||
+ | print " | ||
+ | end | ||
+ | |||
+ | |||
+ | # soma todos os valores do array | ||
+ | function total(ref(array), | ||
+ | | ||
+ | for t = 0 to comprimento-1 | ||
+ | total= total+array[t] | ||
+ | next t | ||
+ | end function | ||
+ | </ | ||
+ | mostra qualquer coisa como\\ | ||
+ | < | ||
+ | 1 | ||
+ | 5 | ||
+ | 4 | ||
+ | 2 | ||
+ | 2 | ||
+ | Soma=14 | ||
+ | </ | ||
+ | ==== Ver também ==== | ||
+ | [[call|Call]], | ||
+ | |||
+ | ==== Desde ==== | ||
+ | 0.9.9.13 |