2.2 Programming Fundamentals Flashcards
Sequence
Executing one instruction after another
Selection
A program branching depending on a condition
IF / ELSE statements.
Iteration
Repeating sections of code - looping.
Types of Iteration
FOR loops
WHILE loops
FOR Loops
AKA count-controlled loops are used when the number of iterations needed are known ahead of the iteration executing.
Example of FOR loops
for i in range(3):
print(“Hello”)
Hello
Hello
Hello
WHILE Loops
Condition-controlled loops are used when the number of iterations needed are not known beforehand as the variable used to determine that changes.
Example of WHILE loops
count= 10
while count>0:
print(count)
count = count-1
print(“Blast off”)
10
9
8
7
6
5
4
3
2
1
Blast off
The 4 Data Types
String
Integer
Float
Boolean
Integer
A whole number, positive or negative. Used for calculations.
Real / Float
A number with a decimal point. Used for calculations.
String
A set of characters.
Boolean
TRUE or FALSE. Used to check if something has happened.
Character
A single alphanumeric character.
Casting
Converting a variable from one data type to another.
x = int(x)
Variables
A value stored in memory that can change while the program is running.
Constants
A value that does not change while the program is running and is assigned when the program is designed.
Assignment
Giving a variable or constant a value.
Subprograms
small programs that are written within a larger, main program to perform a specific task.