What is a program?

 

What is a program?

Programs are made up of statements that the programming language knows and understands.

Just as words are put together to form a sentence, a program puts one or more statements together to form an instruction. Each statement tells the computer to perform a specific task, and the instructions tell a computer what to do.

Statements

Different programming languages use different statements. A few of these are listed in this table:

StatementPurpose
printOutput a message on the screen
inputGet data from the user
if…elseA decision
whileA loop controlled by a decision
forA loop controlled by a counter
defCreate a procedure or function

Examples

The following sentence asks someone to write a message on a whiteboard:

“Please write the words ‘Hello world!’ on the board.”

This sentence is an instruction, which contains a single statement. The statement is ‘write the words’. In Python (3.x), the equivalent statement is print.

print("Hello world!")Entering a command in a human language will cause a program error and the same command needs to be entered in a programming language for the computer to output the desired command.

The following Python (3.x) program contains two instructions, each built up from one statement:

if age >= 17 print("You are old enough to drive a car!")