1. Re: goto / global variables

>> Your proposed "static" keyword is unnecessary because
>> "static" is the *default* in Euphoria. All symbols are "static"
>> unless they are declared with "global" in front of their
>> declaration.
>> For a symbol to be accessible from another file you *must*
>> declare it as "global".

>A static variable is defined in a procedure, but does not lose its
>value after exiting the procedure, in other words :

>integer var
>
>procedure test()
>    integer static_var
>
>    if var=5 then
>        static_var=var
>    end if
>    ?static_var
>end procedure
>
>var=5
>test()
>var=6
>test()

>With static variables, this piece of code would display:
>
>5
>5
>
>However, it gives an error: "static_var has not been assigned a
>value". Which means that variables defined in a procedure are NOT
>static.

This is the problem.... The values don't default to 0 and {}, but there
is a way around this.... (Now that I know that the variables keep there
values)

integer inited
inited = 0

procedure sub()
    atom col

    if not inited then
        col = 7
    end if
    text_color(col)
    puts(1, "\nNow it works!\n")
end procedure

procedure sub2()
   atom bground

    if not inited then
        bground = 0
    end if
    bground = bground + 1
    bk_color(bground)
    puts(1, "Next background color....\n")
end procedure

inited = 1

sub
sub2
sub2
sub2

Notice as long as the variable inited, accessable from the procedures, is
0 then the values are set, once everything has been setup, inited = 1 and
the values are not reset.

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu