Versions Compared

Key

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

...

Code Block
languagepy
# 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
    print(n)
    n = n + 1
end while

# basic repeat loop
n = 1
repeat
    print(n)
    n = n + 1
until n > 10

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

Tests

Code Block
languagepy
# basic if test
if a = b then
    print(’a and b are equal’)
end if

# if test with an else condition
if a = b then
    print(’a and b are equal’)
else print(’a and b are different’)
end if

# if test with an else if and an else condition
if a > 0 then
    print(’a is positive’)
else if a < 0 then
    print(’a is negative’)
else print(’a is null’)
end if

# when statement. The code following the first true expression is
# executed.
when
    a > 0 :
        print(’a is positive’)
        end
    a < 0 :
        print(’a is negative’)
        end
    a = 0 :
        print(’a is null’)
        end
end when

# case statement
case type(x) of
	’number’ :
		print(’x is a number’)
		end
	’date’ :
		print(’x is a date’)
		end
	otherwise :
		stop(’Unsupported type’)
		end
end case



Functions

You can define your own functions  in Macro. Functions can take any number of input arguments and can optionally enforce type-checking on them. A function does not need to have a return value. Only one value can be returned - to return multiple values, return a structure such as a list, vector or definition containing the values.

...