Nepedia
Back to Discover
Fluent Reader
💻

Control flow

technology Maturity 7-9 Next article →

Software follows a specific path to finish its work. This path is known as control flow. Most of the time, a computer follows a straight line. It moves from one command to the very next one. This is called sequential execution.

Programmingloops
Programmingloops

However, code does not always move in a simple line. Sometimes, a command tells the computer to skip ahead or go back. These special commands are called control flow commands. They change the way the computer moves through the instructions.

There are many ways to change this path. A jump is one of the simplest ways. A jump moves the computer to a new spot in the code without asking questions. This is often called an unconditional branch. Other times, the computer makes a choice. This is a conditional branch. It only jumps if a specific rule is met. For example, an "if" statement checks a fact first. If the fact is true, the computer takes one path. If it is false, the computer might take a different path.

Programmingloops
Programmingloops

Programmers have used different tools for this for a long time. In the early days of the Fortran language, there was a tool called an arithmetic if. This checked if a number was negative, zero, or positive. By the year 1990, this tool was considered old and was removed. Later, in Fortran 2018, it was gone for good. Many famous scientists have studied how to write code well. A scientist named Dijkstra even said that the "goto" jump command could be harmful. He wanted code to be more organized and clear.

Computers use many different types of commands to manage flow. A function is a group of code with its own name. When a program calls a function, it jumps to that code. Once the work is done, it returns to where it started.

Programmingloops
Programmingloops

Another tool is a loop. A loop repeats a set of steps many times. A numeric loop might count from one to ten. A condition-controlled loop runs until a rule changes. Some loops can even run forever!

Programmingloops
Programmingloops

These tools help the computer handle complex jobs very quickly.

Control flow is like following a map or a recipe. A recipe tells you to do things in order. But if a recipe says, "If the oven is hot, put in the cake," that is a conditional branch. If a recipe says, "Stir the batter ten times," that is a loop.

Programmingloops
Programmingloops

In the same way, programmers use labels to mark spots on their maps. A label is a name for a specific line of code. This lets the computer know exactly where to jump. Understanding these paths helps us see how all software works.

446 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (1)
File:Programmingloops.svg
Programmingloops.svg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.