Rolando Andrade
Back to Content

What Is Pseudocode? Rules, Examples and Your First Programs: Programming Fundamentals (2)

Learn pseudocode with StepCode: program structure, comments, variables, assignment, Read and Write. Write and run your first programs in the browser.

· 8 min read
What Is Pseudocode? Rules, Examples and Your First Programs: Programming Fundamentals (2)

Pseudocode is a simple language for writing algorithms. It sits between plain English and a real programming language: it has a clear structure, but far fewer rules. After this lesson, you can read and write a complete pseudocode program that asks the user for data, does a calculation and shows the result, and you can run it in your browser.

In this lesson you will:

  • Learn why pseudocode exists and where it fits.
  • Learn the rules of StepCode, the pseudocode this series uses.
  • Split any program into its three parts: input, process and output.
  • Write and run three programs from scratch.

It takes about 40 minutes. You only need the first lesson, where you designed the salary algorithm and saw your first StepCode program.

Why pseudocode exists

In the last lesson, you wrote the salary algorithm in plain English first, and then as a program. Plain English is easy to write but easy to make vague. A programming language is exact, but it has strict rules that get in the way when you are still thinking. Pseudocode gives you the structure of code without the details of any one language.

That makes it a bridge. You write the logic once in pseudocode, and then you can translate it to Python, JavaScript or any other language.

Step 1: Ask English Ask the user for the first number. StepCode Read n1; Python n1 = float(input()) Step 2: Add English Add the two numbers. StepCode total <- n1 + n2; Python total = n1 + n2 Step 3: Show English Show the sum to the user. StepCode Write "The sum is ", total; Python print("The sum is", total)
The same three steps in plain English, in StepCode and in Python. Pseudocode keeps the exact meaning of code, but reads almost like English.

This bridge matters even more now that AI agents write so much code. When you ask an agent for a program, the clearer your steps are, the better its code is. When it gives you code back, you need to read it as a list of steps and check each one. Pseudocode trains exactly that skill: thinking in precise steps without getting lost in the details of a language.

Pseudocode you can run

For years, pseudocode lived only on paper and on whiteboards. Nobody ran it on a computer, so students could not test their algorithms. My course used the pseudocode of PSeInt, a free tool that runs Spanish pseudocode.

For this series, every example uses StepCode, a pseudocode language I built for my students. It follows the same rules as PSeInt, it can use English keywords, and it runs in the browser. Every editor in these lessons runs StepCode, so you can test every idea as you read.

You will find other pseudocodes with different keywords. Do not worry about that. The ideas are the same in all of them, and once you know one, you can read the others.

The rules of StepCode

Each rule below is short. Together, they are everything you need to write your first programs.

Programs start and end

Every program starts with Program and a name, and ends with EndProgram. Every instruction goes between those two lines. This is the smallest complete program:

Edit the code and press Run to try it.

Instructions end with a semicolon

Each instruction ends with a semicolon (;). It tells StepCode where one instruction stops and the next one begins. The Program and EndProgram lines are not instructions, so they have no semicolon.

Comments start with two slashes

A comment is a note for people who read the code. It starts with //, and StepCode ignores everything after it on that line. Use comments to explain why a step exists, or to match lines of code with the steps of your algorithm.

Indentation shows structure

Indentation is the space at the start of a line. Lines inside Program and EndProgram are indented with four spaces, so you can see at a glance which lines belong together. StepCode runs the code without it, but people read code much more easily with it. In later lessons, blocks will go inside other blocks, and indentation will show each level.

Names follow two rules

An identifier is the name you give to something, like a program or a variable. It must start with a letter (or an underscore) and have no spaces. total, n1 and hourlyRate are valid. my name (with a space) and 2name (starting with a number) are not. When a name has several words, join them and start each new word with a capital letter, like hourlyRate.

Valid: hourlyRate starts with a letter and has no spaces.

Type any name, or pick one, to see if StepCode accepts it. Words StepCode already uses, like Write, are not allowed either.

Declare before you use

A variable is a named box that holds one value, like a number or a piece of text. Before you use a variable, you declare it with Define, its name and its data type:

  • Define age As Integer; for whole numbers, like 17.
  • Define price As Real; for numbers with decimals, like 12.5.
  • Define name As String; for text, like "Ana".

You can declare several variables of the same type at once: Define n1, n2, total As Real;. There are more types, and the lesson on variables and data types explains all of them.

Assignment uses an arrow

To store a value in a variable, use an arrow: <- (or ←). Read x <- 5; as “x gets 5”. The right side is calculated first, and then the result goes into the variable on the left, so x <- x + 1; means “x gets its current value plus one”.

How x gets x plus 1, step by step. Step 1: Before the line runs, the box x holds 5. Step 2: First, StepCode reads the right side. x still holds 5, so x + 1 becomes 5 + 1. Step 3: Next, it calculates the right side: 5 + 1 is 6. Step 4: Last, the arrow stores 6 in x. The old 5 is gone.

Last, the arrow stores 6 in x. The old 5 is gone.

Step 4 of 4
The right side is calculated first, with the old value of x. Only then does the arrow put the new value in the box.

Now try it in the editor. Use the step buttons to run one line at a time and watch x change in the Variables panel.

Edit the code and press Run to try it.

Press Run. You should see:

x is 5
Now x is 6

On the right side, you can use the basic math operators: + (add), - (subtract), * (multiply), / (divide) and ^ (power), with parentheses to group. The lesson on operators and expressions covers them all.

Write shows and Read asks

Write shows values in the console. You can list several values separated by commas, and StepCode writes them one after the other on the same line: Write "The sum is ", total;. Notice the space inside the quotes. StepCode adds no spaces for you.

Read waits for the user to type a value and stores it in a variable: Read n1;. The variable must be declared first, and the value is converted to the variable’s type. Always Write a message before a Read, so the user knows what to type.

The three parts of a program

Most programs, from a calculator to a banking app, do three things in order:

  1. Input. The program gets the data it needs, from the user, a file or another program.
  2. Process. The program works with that data to solve the problem.
  3. Output. The program shows, saves or sends the result.
Input, processing and output: the three parts of a program
Input, processing and output: the three parts of a program

In a StepCode program, you can point at each part. The Read lines are the input, the assignments are the process and the final Write is the output. Declarations come before all of them. In Input, process and output you build a complete program around these three parts.

1 Program SumTwoNumbers 2 Define n1, n2, total As Real; 3 Write "Enter the first number:"; 4 Read n1; 5 Write "Enter the second number:"; 6 Read n2; 7 total <- n1 + n2; 8 Write "The sum is ", total; 9 EndProgram Start Declarations Input Process Output End

Press Run next line to start. The user will type 5 and 3.5.

Every line of the sum program has one job. Run it line by line: the input fills n1 and n2, the process fills total, and the output writes the result.

When you read code, from a classmate or from an AI agent, start by finding these three parts. They tell you what the program needs, what it does and what it gives back.

Four kinds of instructions

Every instruction in a program belongs to one of four kinds:

  • Start and end. They mark where the program begins and stops. StepCode uses Program and EndProgram. Python uses indentation. C family languages use braces ({ and }).
  • Assignment. It gives a value to a variable, like total <- n1 + n2;.
  • Input and output. They talk to the user or to files, like Read and Write.
  • Control. They decide which instruction runs next: choosing between paths or repeating steps. You will learn them in the lessons on conditionals and loops.

Guided practice: your first programs

Now you write the code. Each part gives you a problem from the course and a working solution. Type it yourself in the editor before you look at the solution: you learn much more that way.

1. Add two numbers

This was the first example of the unit: ask the user for two numbers and show their sum. It uses every rule from this lesson. Find the comments: they mark the input, the process and the output.

Edit the code and press Run to try it.

Press Run and type 5 and 3.5. You should see:

Enter the first number:
Enter the second number:
The sum is 8.5

For comparison, here is the same program in Python, the language the course used next to pseudocode:

n1 = float(input("Enter the first number: "))
n2 = float(input("Enter the second number: "))
total = n1 + n2
print("The sum is", total)

The steps are the same. Only the words change. You will learn how that translation works in the next lesson.

2. Calculate the area of a triangle

The class activity: calculate the area of a triangle from its base and its height. The formula is base times height, divided by 2. You wrote these steps in plain English in exercise 3 of the last lesson.

Edit the code and press Run to try it.

Run it with 10 and 4. You should see:

Base of the triangle:
Height of the triangle:
The area is 20

3. Greet the user by name

Programs work with text too. This one, from the practice guide, asks for a first name and a last name and answers with a greeting. The variables are String, and the Write puts a space between the two names.

Edit the code and press Run to try it.

Run it with Pedro and Perez. You should see:

Enter your first name:
Enter your last name:
Hello Pedro Perez

Try removing the " " in the middle of the last line and run it again. You get Hello PedroPerez, because StepCode adds no spaces for you.

Common mistakes

If you see "total" is not declared., you used a variable without a Define. Add a line like Define total As Real; before the first line that uses it. StepCode checks this before the program runs.

If you see I did not expect "=" here., you used = to assign a value. Many languages, like Python, assign with =. StepCode uses the arrow, so write total <- 5;. In StepCode, = compares two values, which you will use in conditionals.

If you see This statement is missing its ";"., an instruction has no semicolon. The editor marks the line. Add the ; at the end of it. You saw this error in the first lesson.

If the output looks glued together, like The sum is8.5, you forgot a space inside the quotes. Write "The sum is " with the space before the closing quote.

Pseudocode or programming language?

Pseudocode Programming language
Made for People who design and share algorithms Computers that run programs
Rules Few and forgiving Many and strict
Keywords Close to plain language (Read, Write) Set by each language (input, print)
Runs on a computer Only with a tool like StepCode or PSeInt Yes, that is its purpose
Used for Learning, planning, explaining Building real software

Pseudocode does not replace a programming language. It is where you think before you build. Professional programmers still write pseudocode in comments, on whiteboards and in the instructions they give to AI agents.

Practice exercises

These exercises come from the course practice guide. Try each one in an empty editor first. Then open the solution and compare. There are many correct solutions to each problem; yours does not need to match line by line.

Exercise 1. Ask the user for three numbers. Add the first two and divide the sum by the third. With 5, 3.5 and 2, the result is 4.25.

Solution to exercise 1
Edit the code and press Run to try it.

With 5, 3.5 and 2, you should see:

Enter the first number:
Enter the second number:
Enter the third number:
The result is: 4.25

Exercise 2. Ask the user for their name and their age, and show both in one sentence. Use String for the name and Integer for the age.

Solution to exercise 2
Edit the code and press Run to try it.

With Pedro and 17, you should see:

Enter your name:
Enter your age:
I am Pedro and I am 17 years old

Exercise 3. Scientists on a hidden island found a particle called the Energion. It releases energy when it breaks apart. Calculate that energy with Einstein’s formula, E = mc², where m is the mass in kilograms and c is the speed of light, 299792458 meters per second.

Solution to exercise 3
Edit the code and press Run to try it.

With a mass of 0.001 (one gram), you should see:

Mass of the Energion in kilograms:
The Energion releases 89875517873681.77 joules

That is about 90 trillion joules from one gram. The last digits come from small rounding in how computers store decimal numbers. You solve this problem again with a constant in Variables and data types.

Exercise 4. In a world where snails are the fastest animals, you organize the Great Snail Race. Each snail moves at a constant speed. Calculate how long a snail takes to finish the track. In physics, time equals distance divided by speed.

Solution to exercise 4
Edit the code and press Run to try it.

With a track of 3 meters and a speed of 0.002 meters per second, you should see:

Length of the track in meters:
Speed of the snail in meters per second:
The snail needs 1500 seconds

What happens if a snail has a speed of 0? Try it. You get the runtime error from the first lesson.

What you learned

  • Pseudocode is a bridge between plain language and code: exact enough to run, simple enough to read.
  • A StepCode program starts with Program Name and ends with EndProgram, and each instruction ends with ;.
  • You declare variables with Define, store values with <-, show values with Write and ask for values with Read.
  • Most programs have three parts in order: input, process and output. Finding them is the first step to reading any program.

Next steps

  • Continue with Programming languages, where you learn how code like this becomes something a computer runs, and how to translate pseudocode to Python.
  • Go back to Algorithms if you want to review the four traits and the three kinds of errors.

If you enjoy the content, please don’t hesitate to subscribe and leave a comment! I would love to connect with you and hear your thoughts on the topics I cover.

Interested in working together? Check out my services and pricing to see how we can collaborate on your next project. Let's Build