Design to code

Start with a problem you understand. Make the steps precise, use blocks to represent the algorithm and read the pseudocode Pseudly generates. Then check its behaviour. The same algorithm can be translated into different programming languages.

A packing description leads to real Pseudly blocks and generated pseudocode, then equivalent JavaScript, Python and C++ code. Python has the heaviest outline. Testing and refinement return to the original design.
One algorithm, several implementations. Open the image for a larger view or use the printable A4 landscape PDF.

Explain the decision

Pack a school bag. If rain is forecast, pack a raincoat; otherwise pack a hat. In this simplified model, a forecast with no rain means we choose a hat. We are not claiming every dry day is sunny.

The example starts with a true forecast and an empty bag. It adds exactly one item, then prints the bag. Change the forecast to false and predict the alternative branch. Read the pseudocode before running, follow the highlighted instructions and explain any difference from your prediction.

The language panels illustrate translations of the same algorithm. Pseudly generates the pseudocode; these illustrations do not mean it exports JavaScript or C++.

Real blocks and their pseudocode

Actual Pseudly SET, IF ELSE, list append and PRINT blocks for the packing algorithm
SET rainForecast TO TRUE
SET bag TO []
IF rainForecast THEN
    SET bag TO (APPEND "raincoat" TO bag)
ELSE
    SET bag TO (APPEND "hat" TO bag)
END IF
PRINT bag
The blocks and pseudocode come from Pseudly’s generator and exporter.

Appending in Python: bag is a list object. Use bag.append("raincoat") in the true branch and bag.append("hat") in the false branch. The method changes the existing list; do not assign its return value to bag. The real pseudocode above uses Pseudly’s value-returning APPEND expression, so SET retains that result. Both versions choose the same item in this example.

Implement in a language

Each implementation starts with the same forecast and an empty bag. A true forecast packs a raincoat; false packs a hat. Printed list formatting differs, while the selected item is equivalent. The C++ poster shows the body of main; the complete program is below.

JavaScript

const rainForecast = true;
let bag = [];
if (rainForecast) {
  bag = [...bag, "raincoat"];
} else {
  bag = [...bag, "hat"];
}
console.log(bag);

Python

rainForecast = True
bag = []
if rainForecast:
    bag.append("raincoat")
else:
    bag.append("hat")
print(bag)

C++

#include <iostream>
#include <string>
#include <vector>

int main() {
    bool rainForecast = true;
    std::vector<std::string> bag;
    if (rainForecast) {
      bag.push_back("raincoat");
    } else {
      bag.push_back("hat");
    }
    for (const auto& item : bag)
      std::cout << item << '\n';
    return 0;
}

Apply the idea

Use the Input, Process, Output worksheet to identify the required data, processing and results before designing the algorithm.

Use the blank worksheet to describe a problem, design its pseudocode and plan a Python implementation. Identify sequence, selection and iteration where they are needed. State assumptions and predict results before running.

Pseudly

a bridge between blocks and code

Version 0.7.2 — 24 November 2026

© Pseudly 2025-26

Release Notes

Full History

Credits

Pseudly is developed by Peter Hurwood. Thanks to the maintainers of the software used to build and run it.

Licence and copyright notices · JavaScript · Python · Font Awesome Free · Quill and bundled components