Introduction to programmingWhat is a program?

Programming is writing computer code to create a program, in order to solve a problem. Programs consist of a series of instructions to tell a computer exactly what to do and how to do it.

Part of Computer ScienceProgramming

What is a program?

are made up of 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 . Each statement tells the computer to perform a specific task, and the instructions tell a computer what to do.

Statements

Different 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
Statementprint
PurposeOutput a message on the screen
Statementinput
PurposeGet data from the user
Statementif…else
PurposeA decision
Statementwhile
PurposeA loop controlled by a decision
Statementfor
PurposeA loop controlled by a counter
Statementdef
PurposeCreate 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 (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!")