Var » History » Version 4
Per Amundsen, 05/28/2014 07:42 AM
1 | 1 | Per Amundsen | _Added in 1.8.8_ |
---|---|---|---|
2 | |||
3 | */var [-sg] <%var> [[= ]value]* |
||
4 | |||
5 | Sets the value of local variable %var to the specified value. |
||
6 | |||
7 | *Switches* |
||
8 | |||
9 | -s - Display variable assignment value. |
||
10 | -g - Creates a global variable instead. |
||
11 | 4 | Per Amundsen | -n - Treat the value as plain text, even if arithmetic operators are used. |
12 | 1 | Per Amundsen | |
13 | *Parameters* |
||
14 | |||
15 | <%var> - The variable to set. |
||
16 | [[= ]value] - Value to set the variable to. (can be a single arithmetic expression, see [[Arithmetic Operators]]) |
||
17 | |||
18 | *Example* |
||
19 | |||
20 | 2 | Per Amundsen | <pre> |
21 | 3 | Per Amundsen | alias factorial { |
22 | 1 | Per Amundsen | var %result = 1, %x = $1 |
23 | while (%x) { |
||
24 | var %result = %result * $v1 |
||
25 | dec %x |
||
26 | } |
||
27 | return %result |
||
28 | } |
||
29 | 3 | Per Amundsen | |
30 | ;Returns 3628800 |
||
31 | //echo -ag $factorial(10) |
||
32 | 2 | Per Amundsen | </pre> |