Skip to content
简体中文
All chapters
CHAPTER 0212 min

Programming

Turn an idea into steps a machine can follow

You don't need to memorize a language here. Meet the common building blocks of code and learn to trace what they do. This makes your requests clearer and the changes AI makes easier to understand.

By the end, you can
Recognize variables, conditions, loops, functions, and data structures
Distinguish languages, runtimes, and dependencies
Translate a vague idea into actions and expected results
02.01

A program needs precise steps

A person may guess what “tidy my list” means. A computer needs rules: which tasks, what order, and what to do in each situation. Source code expresses those rules in a programming language.

AI can help write code, but it may also guess the information you leave out. Breaking a goal into inputs, processing, and outputs is a useful way to think before choosing a language.

In a familiar situation

Input: product prices. Process: keep products within a budget. Output: a list of qualifying products.

Take this with you · Start with concrete inputs and expected results.

Source codeInstructionInput / output
02.02

Why are there different languages?

JavaScript is common for webpage interactions, Python for scripts and data processing, and SQL for database queries. Their ecosystems and runtimes differ, but many uses overlap.

Choosing a language means considering where the result will run, what the existing project uses, and which tools are available. Ask AI to inspect an existing project before deciding how to change it.

In a familiar situation

Changing a webpage button starts with understanding the existing frontend, not automatically creating an unrelated Python project.

Take this with you · Define the goal and environment before selecting an implementation language.

JavaScriptPythonSQLRuntime
02.03

Variables, conditions, and loops

A variable names a value, such as budget. A condition selects a branch, such as price <= budget. A loop applies work repeatedly, such as checking every price in a list.

These often work together: read each price, compare it to the budget, and keep it if it qualifies. Even before understanding every symbol, look for the data, decisions, and repeated steps.

In a familiar situation

With budget 30 and prices 12, 35, and 20, keep 12 and 20. Change the budget to 40 and the output changes.

Take this with you · Trace code with a concrete input instead of guessing its behavior.

VariableCondition / ifLoopComparison
Test the idea yourself

Step through a small program

Predict the output, then check the prices one by one. Change the budget to see how a variable affects conditions and results.

Try this · Use Next step to check all the prices and see which ones are kept.
budget = 25
prices = [12, 35, 20, 48, 8]

for each price in prices:
 if price <= budget:
 keep(price)
12Waiting
35Waiting
20Waiting
48Waiting
8Waiting
0/5

Output: []

This runs a fixed filtering algorithm with real calculated results, not arbitrary user code.

02.04

Functions and data structures

A function gives a name to a reusable operation. It can take inputs and return a result. Arrays hold ordered collections; objects or dictionaries map names to values; trees represent hierarchies.

The structure you choose affects later operations. A list can be an array of task objects, each with an id, title, and completion status. Stable IDs identify which item to update.

In a familiar situation

A task might be { id: 7, title: 'Practice adding', done: false }. Completing it finds id 7, changes done, then updates the interface.

Take this with you · Ask how the data is organized before asking for a line-by-line syntax lesson.

FunctionArrayObjectData structureTree
02.05

How does source code run?

Source code needs suitable execution tools. Compiling transforms code into another form; interpreters and runtimes execute it. Real implementations often combine approaches rather than belonging to two rigid categories.

A terminal accepts text commands. Commands run in a working directory, so location matters. Keep the full error and command location when asking for help.

In a familiar situation

Running npm run dev in this project's web folder starts the configured development server. The same command outside the project may not work.

Take this with you · For a startup problem, report the system, project directory, command, and full error.

CompileInterpretTerminalPathWorking directory
02.06

Combine existing tools and keep versions

Libraries provide reusable functionality. Dependencies are the libraries and tools a project requires. Installing them makes them available; version differences can change behavior, so projects record their dependencies and versions.

Git records changes so you can compare and restore versions. Ask AI for small, checkable changes and keep working checkpoints rather than losing track of what changed.

In a familiar situation

Before adding deletion: inspect the project, preserve the working version, change the feature, and check that adding and completing still work.

Take this with you · Writing code is only part of the job. Running it, inspecting changes, and checking behavior matter too.

LibraryDependencyGitVersionTest
A new situation. What do you think?

The rule keeps prices no greater than a budget of 20. Which of 12, 35, and 20 remain?

Choose an answer before reading the explanation.

Turn your knowledge into a useful brief

Ask AI to add task completion and restoration. Describe the whole interaction.

Think first, then uncover help as needed. Later chapters expect more complete descriptions and clearer checks.

1 A direction2 A framework3 An example prompt
Try real events and state changes in the list project.Use it in a project
Give your curiosity another turnGo further

Bring this chapter's context to your AI. Going deeper is optional; you can keep reading without it.

Explain variables, conditions, loops, and functions using packing a bag, one idea at a time.

One approach you can make your own
I'm learning computers and AI-assisted programming from scratch. In this chapter I learned:
Programming:Recognize variables, conditions, loops, functions, and data structures;Distinguish languages, runtimes, and dependencies;Translate a vague idea into actions and expected results

Explain variables, conditions, loops, and functions using packing a bag, one idea at a time.

Check my understanding first. Explain one small question at a time with a concrete example and the limits of any analogy. Ask a scenario question, then adapt to my answer. Distinguish facts, guesses, and uncertainty; suggest hands-on ways to check. Confirm the version before giving tool-specific advice, and don't invent features or references.

Complete this chapter

Mark the sections as read, finish the experiment, and pass the scenario check to record completion. You can visit the next chapter at any time.

0/6 sectionsTest a principleExplain a situation

Read the original references

This is an introduction. These official resources help you check details and explore further.

MDN · JavaScript Guide

One machine can follow your steps. Next, let's make two machines communicate.