Skip to content

Getting Started

Welcome to Common Pseudocode! This guide will help you understand the fundamentals of the language.

Common Pseudocode works like JavaScript, where each new line is treated as a statement with an implicit “semicolon” at the end. There’s no need for explicit statement terminators.

Indentation is done Python-style, but without the need for the : at the end of parent statements. Proper indentation is crucial for defining code blocks.

Let’s start with a simple “Hello World” program:

output "Hello, World!"

That’s it! The output statement displays text to the user.

Comments help document your code and are ignored during execution.

Single-line comments:

// This is a single-line comment
x = 5 // This is an inline comment

Multi-line comments:

/*
This is a multi-line comment
that spans multiple lines
*/
x = 10

Declare a variable without an initial value:

define variableName

Assign a value to a variable:

newNumber = 7
currentNumber = newNumber

Example with define:

define counter
define userName
define isValid
counter = 0
userName = "John"
isValid = true

Common Pseudocode supports several basic data types:

age = 25
price = 19.99

Strings can be enclosed in single quotes, double quotes, or backticks:

name = "John"
greeting = 'Hello'
message = `Welcome!`

Multi-line strings:

`
This is a multiline string
that spans multiple lines
`

Or using triple quotes:

"""
This is also a multiline string
"""
isActive = true
isComplete = false

Note: true, True, and TRUE are all valid (same for false).

Convert between types when needed:

stringValue = "123"
numValue = convert stringValue to number // or number(stringValue)
stringFromNum = convert age to string // or string(age)

Reading user input:

input userInput

Prompting for input:

output "Please enter your name: "
input userName

Displaying output:

output "Hello, " userName "!"

Define values that cannot be changed:

constant PI = 3.14159
constant MAX_USERS = 100
sum = 1 + 1 // Addition
diff = 10 - 5 // Subtraction
product = 3 * 4 // Multiplication
quotient = 10 / 2 // Division
power = 2 ^ 3 // Exponentiation (also ** or "to the power of")
remainder = 10 % 3 // Modulus (also "modulus" or "remainder after")
greeting = "Hello" " " "World" // Results in "Hello World"
num = 10
message = "The number is {num}" // Results in "The number is 10"
num = 5
num++ // Same as num = num + 1
num *= 3 // Same as num = num * 3
num ^= 2 // Same as num = num ^ 2

Now that you understand the basics, explore these topics: