Programming Concepts
The building blocks every program is made of: data types, the three structures, and named blocks of code.
RUN THE PSEUDOCODE
Write the pseudocode your syllabus uses and press Run. Assignment is the arrow — type <- and it works the same as ←. Both syllabuses are accepted, so OUTPUT and PRINT both work; where a word differs from the one the exam prints, the runner says so.
Press Run to see what it doesTotal ← 0
FOR Count ← 1 TO N
Total ← Total + Count
NEXT Count
OUTPUT TotalSTARTN = 5
| Count | Total | OUTPUT |
|---|---|---|
One row per pass through the loop. Leave a cell blank if it does not change on that pass.
//The three loops, and when to use each
Count-controlled when you know how many times. Pre-condition (WHILE) when it might not run at all. Post-condition (REPEAT) when it must run at least once.
FOR i ← 1 TO 10 known number of times
...
NEXT i
WHILE Answer <> "y" DO may run ZERO times
...
ENDWHILE
REPEAT always runs AT LEAST once
...
UNTIL Answer = "y"//DIV and MOD
DIV gives the whole-number part of a division; MOD gives the remainder. MOD 2 is how you test for even or odd.
17 DIV 5 = 3 17 MOD 5 = 2
IF Number MOD 2 = 0 THEN OUTPUT "Even"//Validation vs verification
Validation asks 'could this be sensible?' — range, length, type, presence, format and check digit. Verification asks 'was it entered correctly?' — double entry, or a visual check by a human. They are not the same thing and exams test that you know it.
//Local vs global
A local variable exists only inside its procedure and cannot be seen outside — safer, because nothing else can change it by accident. A global variable can be used anywhere, which is convenient but makes bugs harder to find.
KEY TERMS
CHECK YOURSELF
1.A birth year of 3025 is entered. Which check would reject it?
2.Typing a password twice to make sure it matches is:
3.What does 17 MOD 5 give?