VAR Variables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

VAR Variables

Carl Sebeny
Why does the following macro code display the result
of 10 instead of 20?

var x;
x=10;
f();
print (x);
exit("Terminating normally...");
function f(){
    x = 20;
}
Reply | Threaded
Open this post in threaded view
|

Re: VAR Variables

Michael Schmid
Hi Carl,

as I understand it, global variables should be declared with
"var" OUTSIDE any macro.

so, you can have:

var x;
macro 'test' {
   x=10;
   f();
   print (x);
   exit("Terminating normally...");
}
function f(){
     x = 20;
}

Michael
________________________________________________________________

On 17 Sep 2008, at 14:54, Carl Sebeny wrote:

> Why does the following macro code display the result
> of 10 instead of 20?
>
> var x;
> x=10;
> f();
> print (x);
> exit("Terminating normally...");
> function f(){
>     x = 20;
> }