Wiki
Show
Ignore:
Timestamp:
03/20/10 04:42:28 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Improvements to the How-To's.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/HowTo/101-WriteBasicSyntax.cobra

    r2127 r2335  
    5252 
    5353        # If-else statement 
     54        # See also: "Make An If Else Ladder" How To 
    5455        if a > b 
    5556            print 'a is greater' 
     
    5758            print 'a is not greater' 
    5859 
    59         # Can put target on same if target is just one statement 
     60        # Can put target on same line if the target is just one statement 
    6061        if a > b, print 'a is greater' 
    6162        else, print 'b is greater or equal' 
     
    6465        while a > b 
    6566            a -= 1  # augmented assignment 
     67         
     68        # While loop in one line 
    6669        while a > b, a -= 1 
     70 
     71        # Parallel assignment 
     72        a, b = 1, 2 
     73         
     74        # Lists -- see the "Use Lists" How To for more info 
     75        t = ['a', 'b', 'c'] 
     76        for letter in t, print letter 
     77 
     78        # Dictionaries 
     79        d = {'a': 1, 'b': 2} 
     80        assert d['a'] == 1 and d['b'] == 2 
     81        for key, value in d 
     82            print '[key] = [value]'  # string interpolation 
     83 
     84        # Sets -- like lists, but no repetition 
     85        letters = {'a', 'b', 'c'} 
     86        assert 'a' in letters 
     87        for letter in letters, print letter 
    6788 
    6889        # Line continuation is implicit with parenthesized arguments