Getting Started
Welcome to Common Pseudocode! This guide will help you understand the fundamentals of the language.
General Notes
Section titled “General Notes”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.
Your First Program
Section titled “Your First Program”Let’s start with a simple “Hello World” program:
output "Hello, World!"That’s it! The output statement displays text to the user.
Comments
Section titled “Comments”Comments help document your code and are ignored during execution.
Single-line comments:
// This is a single-line commentx = 5 // This is an inline commentMulti-line comments:
/*This is a multi-line commentthat spans multiple lines*/x = 10Variables and Assignment
Section titled “Variables and Assignment”Declare a variable without an initial value:
define variableNameAssign a value to a variable:
newNumber = 7currentNumber = newNumberExample with define:
define counterdefine userNamedefine isValid
counter = 0userName = "John"isValid = trueData Types
Section titled “Data Types”Common Pseudocode supports several basic data types:
Numbers
Section titled “Numbers”age = 25price = 19.99Strings
Section titled “Strings”Strings can be enclosed in single quotes, double quotes, or backticks:
name = "John"greeting = 'Hello'message = `Welcome!`Multi-line strings:
`This is a multiline stringthat spans multiple lines`Or using triple quotes:
"""This is also a multiline string"""Booleans
Section titled “Booleans”isActive = trueisComplete = falseNote: true, True, and TRUE are all valid (same for false).
Type Conversion
Section titled “Type Conversion”Convert between types when needed:
stringValue = "123"numValue = convert stringValue to number // or number(stringValue)stringFromNum = convert age to string // or string(age)Input and Output
Section titled “Input and Output”Reading user input:
input userInputPrompting for input:
output "Please enter your name: "input userNameDisplaying output:
output "Hello, " userName "!"Constants
Section titled “Constants”Define values that cannot be changed:
constant PI = 3.14159constant MAX_USERS = 100Basic Operators
Section titled “Basic Operators”Arithmetic Operators
Section titled “Arithmetic Operators”sum = 1 + 1 // Additiondiff = 10 - 5 // Subtractionproduct = 3 * 4 // Multiplicationquotient = 10 / 2 // Divisionpower = 2 ^ 3 // Exponentiation (also ** or "to the power of")remainder = 10 % 3 // Modulus (also "modulus" or "remainder after")String Concatenation
Section titled “String Concatenation”greeting = "Hello" " " "World" // Results in "Hello World"num = 10message = "The number is {num}" // Results in "The number is 10"Compound Assignments
Section titled “Compound Assignments”num = 5num++ // Same as num = num + 1num *= 3 // Same as num = num * 3num ^= 2 // Same as num = num ^ 2What’s Next?
Section titled “What’s Next?”Now that you understand the basics, explore these topics:
- Comments and Formatting - Detailed comment syntax
- Data Types - In-depth look at all data types
- Operators - Complete operator reference
- Control Flow - if/else statements and more
- Loops - Iteration and repetition