Changeset 2335 for cobra/trunk/HowTo/101-WriteBasicSyntax.cobra
- Timestamp:
- 03/20/10 04:42:28 (2 years ago)
- Files:
-
- 1 modified
-
cobra/trunk/HowTo/101-WriteBasicSyntax.cobra (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/HowTo/101-WriteBasicSyntax.cobra
r2127 r2335 52 52 53 53 # If-else statement 54 # See also: "Make An If Else Ladder" How To 54 55 if a > b 55 56 print 'a is greater' … … 57 58 print 'a is not greater' 58 59 59 # Can put target on same iftarget is just one statement60 # Can put target on same line if the target is just one statement 60 61 if a > b, print 'a is greater' 61 62 else, print 'b is greater or equal' … … 64 65 while a > b 65 66 a -= 1 # augmented assignment 67 68 # While loop in one line 66 69 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 67 88 68 89 # Line continuation is implicit with parenthesized arguments



