Elements of a program


Knowing how a program runs and what data it relies on is an important first step toward understanding how to create your own programs.

A single instruction in a program is called a statement. A statement usually has a character or line spacing that marks where the instruction ends, or terminates. How a program terminates varies with each language.

Programs are data driven

Most programs rely on using data that's obtained from a user or another source, where statements might rely on such data to carry out instructions. Data can change how a program behaves, so programming languages come with a way to temporarily store data for later use.

The data is stored in a statement called a variable. Variables are statements that instruct a device to save data in its memory. Variables in programs are similar to those in algebra, where they have a unique name and their value might change over time.

Flow control

Some statements might not be executed by a device. This usually happens either by design, as written by the developer, or by accident, as the result of an unexpected error.

Controlling the flow of an application makes it more robust and maintainable. Changes in control ordinarily occur when certain conditions are met. A common statement in modern programming languages, to control how a program is run, is the if...else statement. You'll learn more about this type of statement in subsequent lessons.