Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


and by case do else end export extern for function global if import in include inline loop nil not object of on or otherwise repeat return task tell then to until when while


To write comments, use the character #. Any text from this character to the end of the line is ignored. Each line to be commented must be preceded by the # character, i.e. C-like multi-line comments are not allowed.

Code Block
titleMacro comments
# Now plot the field
plot (Z500) # using default contours 

Variables and scope

Variables declared in the program scope are not visible to functions unless they are declared global. This is usually discouraged, but an example is here:

Code Block
global my_var = 5

function modify_my_var()
    my_var = 6
end modify_my_var

print(my_var)    # 5
print(my_var)    # 6

If the word global had not been present, the last line would have printed 5, because the function would have simply set the value of a local variable and not touched the one declared outside.


Code Block
# basic for loop
for i = 1 to 4 do
    print (i)
end for

# for loop with a list
for i = 1 to count(thisList) do
    print (i, " : ", thisList[i])
end for

# for loop using dates with a step
for day = 2003-01-24 to 2003-02-14 by 3 do
    print (day)
end for

# basic while loop
n = 1
while n <= 10 do
    n = n + 1
end while

# basic repeat loop
n = 1
    n = n + 1
until n > 10

# loop - can be used on lists, fieldsets and geopoints
loop element in thisList
end loop