The Cobra Programming Language
How To
Print Hello World
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Make A Class Hierarchy
Use Nil And Nilable Types
Use Dynamic Typing
Declare Variable Number Of Args
Read And Write Files
Check Inheritance And Implementation
Pass References To Methods
Translate Pseudo Code To Cobra1
Translate Pseudo Code To Cobra2
Implement IEnumerable1
Implement IEnumerable2
Iterate Through Recursive Data With Yield
Make A Collection Class
Declare Contracts
Threads
Win Forms
GTK
Access MySQL
""" This is a doc string for the whole module. """ class Person """ This is a class declaration. """ var _name as String # declare a class variable. every instance of Person will have a name var _age as int def 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' # While loop while a > b a -= 1 # augmented assignment while a > b, a -= 1 # Line continuation is done with an underscore # Next line is indented the same or more p = Person('Bob', _ 30)