""" This is a doc string for the whole module. """ class Person """ This is a class declaration. """ var _name as String # declare an object variable. every instance of Person will have a name var _age as int cue init(name as String, age as int) _name = name _age = age def sayHello # This is a method # In strings, anything in brackets ([]) is evaluated as an expression, # converted to a string and substituted into the string: print 'Hello. My name is [_name] and I am [_age].' def add(i as int, j as int) as int """ Adds the two arguments and returns their sum. """ return i + j class Program def main is shared # Create an instance p = Person('Bob', 30) # Invoke a method p.sayHello # Invoke a method with arguments print p.add(2, 2) # Assert the truth of something assert p.add(2, 2)==4 # If statement a = 2 b = 1 if a > b print 'a is greater' print 'b is smaller' # If-else statement if a > b print 'a is greater' else print 'a is not greater' # Can put target on same if target is just one statement if a > b, print 'a is greater' else, print 'b is greater or equal' # While loop while a > b a -= 1 # augmented assignment while a > b, a -= 1 # Line continuation is implicit with parenthesized arguments p = Person('Bob', 30) # Line continuation can be done explicitly with an underscore # The next line is indented the same or more b = a * _ 10 |