Computer science
Pseudocode
Plan first, code later: how to sketch an algorithm in clear steps before you write a single line of code.
Before a house is built, an architect draws a plan. Before a program comes to life, programmers do the same: they first sketch their idea in simple, clearly ordered steps, without worrying about the rules of any programming language. This sketch is called pseudocode. It already looks almost like a program, but it is meant for humans, not computers. Here you will learn how to design with it before you type a single line of real code.
What is pseudocode?
Pseudocode is a mix of everyday language and program structure. You write each step on its own line, use clear instructions such as SET points TO 0 or READ a number, and indent steps that belong together. There are no strict grammar rules: what matters is that every step is unambiguous and a person can read the sequence smoothly. A computer cannot run pseudocode directly, and that is exactly the point. You get to focus entirely on the logic instead of semicolons and brackets.
The building blocks: IF, WHILE, FOR
Three keywords show up in almost every piece of pseudocode, and real programming languages use the very same words: IF, WHILE and FOR. IF checks a condition and runs steps only when it holds: IF it is raining, take the umbrella. If you also need a plan B, add ELSE: IF it is raining, take the umbrella, ELSE take the sunglasses. Of the two branches, exactly one always runs. WHILE repeats steps as long as a condition is met: WHILE the water is not boiling, wait. And FOR repeats something a fixed number of times: FOR each of the 5 tasks, read it and solve it. Many people write REPEAT 5 TIMES instead, which means the same thing. With these building blocks and a few simple instructions you can describe an astonishing number of algorithms.
Independent of any programming language
The best thing about pseudocode: it belongs to no programming language. One person can turn the same draft into Python, another into Java or JavaScript, and the logic stays exactly the same. That is why pseudocode appears in textbooks, in exams and on whiteboards when teams design a solution together. It has one more advantage: you can trace it by hand. Take an example number, walk through it line by line and note how the values change. You will catch thinking errors on paper, long before you would have to hunt for them in real code.
Exercises
0 of 6 solvedTime to try it yourself. You can't break anything, every attempt counts.
What is pseudocode?
You want to express in pseudocode: only if the password is correct, open the door. Which keyword fits?
Trace the pseudocode by hand: SET x TO 4. REPEAT 3 TIMES: ADD 2 TO x. What is the value of x at the end?
Complete: steps that are repeated as long as a condition holds start in pseudocode with ….
Trace this: SET x TO 7. IF x IS GREATER THAN 5: DOUBLE x. ELSE: ADD 1 TO x. What is the value of x at the end?
Match each keyword to its meaning.