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:
Statement | Purpose |
---|---|
Output a message on the screen | |
input | Get data from the user |
if…else | A decision |
while | A loop controlled by a decision |
for | A loop controlled by a counter |
def | Create 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!")
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!")