CT: Quick Refresher Syntax

TIP

How to use: Review this before solving any tracing problem.


1. Variables & Types

  • Assignment: Var = Value
  • Integers: 0, 1, -5
  • Strings: "Hello"
  • Booleans: True, False
  • Lists: [1, 2, 3]

2. Operators

  • Math: +, -, *, /
  • Modulus: % (Remainder)
  • Comparison: >, <, >=, <=, ==, !=
  • Logic: and, or, not

3. Conditionals

If (Condition):
    Do A
Else:
    Do B

4. Loops

While Loop

While (Condition):
    Body
    Update

For Loop

For i in Range(Start, End):
    Body
  • Note: Usually includes Start, excludes End (depending on language, but in CT pseudocode often inclusive. Check context!).

5. List Operations

  • Access: L[i]
  • Length: Len(L)
  • Append: L = L + [Item]
  • Slice: L[Start : End]

6. Standard Algorithms

  • Summing: S = S + x
  • Counting: C = C + 1
  • Max: If x > Max then Max = x
  • Min: If x < Min then Min = x

7. Dictionaries

  • Init: D = {}
  • Access: D[key]
  • Update: D[key] = value
  • Check: if key in D
  • Keys: keys(D)
  • Values: values(D)

8. Procedures

  • Definition:
    Procedure Name(Arg1, Arg2)
        Body
        return Result
    End Name
    
  • Call: Val = Name(X, Y)