2 2-Programming-Fundamentals 250009778
2 2-Programming-Fundamentals 250009778
2 PROGRAMMING FUNDAMENTALS
DATA TYPES OPERATORS
These condition controlled loops would IF/ELSE AND SWITCH/CASE FOR SELECTION
check if a password’s correct:
Selection can be shown using IF/ELSE or SWITCH/CASE
while answer != ”letmein123” IF ELSE SWITCH/CASE
answer=input(“Enter password”) If choice == “a” then Switch entry:
endwhile print(“You chose A”) case “A”:
elseif choice==”b” then print(“You chose A”)
print(“You chose B”) case “B”:
do else print(“You chose B”)
answer=input(“Enter password”) print(“Unrecognised choice”) default:
until answer==”letmein123” print(“Unrecognised choice”)
2.2 PROGRAMMING FUNDAMENTALS CONTINUED
SUB PROGRAMS RECORDS
Procedures are a set of instructions stored under a name so that you
can call the procedure to run the whole set of instructions. Records are a data structure used to store
A function is like a procedure but always returns a value. a collection of data. They can store
Parameters are variables used to pass values into a function or information of different data types.
procedure. Field = each item in a record is a field.
Each field has a name and data type.
A procedure with parameters A procedure without parameters
procedure intro (name) procedure intro () A record can be created like this:
print(“Hello “ +name) print(“Hello”)
print(“Welcome to the game”) print(“Welcome to the game”) record students
endprocedure endprocedure int student_number
string student_name
Functions must take at least one parameter and must return a value: bool passed_test
function double(number) endrecord
print number*3
endfunction
Data can be assigned using variables: