Programming Concepts Flashcards
All 24 cards in this deck
What is nested iteration?
e.g. a loop of 4 stars inside a loop of 3 rows
A loop placed inside another loop; the inner loop runs fully on every pass of the outer loop (here, 12 stars).
What is a variable in programming?
A named memory location whose value can change while the program is running.
What is a constant in programming?
A named value that is set once and cannot change while the program is running.
Give one reason to use a constant instead of a variable in a program.
The value cannot be changed accidentally, and it only needs editing in one place.
What is an assignment statement?
A statement that gives a value to a variable. In AQA pseudo-code it uses
←, e.g.score ← 0.True or false? In AQA pseudo-code,
=is used to assign a value to a variable.False.
=tests whether two values are equal;←is used for assignment, e.g.total ← 0.Name the three basic programming constructs.
Sequence, selection (choice) and iteration (repetition).
Which construct do the pseudo-code keywords
IF,ELSE IFandELSEbelong to?Selection.
Which construct do the pseudo-code keywords
FOR,WHILEandREPEAT … UNTILbelong to?Iteration.
What is the difference between definite and indefinite iteration?
Definite (count-controlled) iteration repeats a set number of times, e.g. a
FORloop. Indefinite (condition-controlled) iteration repeats until or while a condition is met, e.g.WHILEorREPEAT … UNTIL.What is the difference between a
WHILEloop and aREPEAT … UNTILloop?WHILEtests its condition at the start, so the code inside may run zero times.REPEAT … UNTILtests its condition at the end, so the code inside always runs at least once.How is a selection with more than two outcomes written in AQA pseudo-code?
e.g. grade A if score is 80+, B if 60+, otherwise C
- Test the first condition:
IF score ≥ 80 THEN OUTPUT 'A' - Add further tests:
ELSE IF score ≥ 60 THEN OUTPUT 'B' - Catch the rest and close:
ELSE OUTPUT 'C'thenENDIF
- Test the first condition:
How is a count-controlled loop written in AQA pseudo-code?
e.g. output the numbers 1 to 5
- Set the counter, start and end:
FOR i ← 1 TO 5 - Put the repeated code inside:
OUTPUT i - Close the loop:
ENDFOR
- Set the counter, start and end:
True or false? A
FORloop can only count up in steps of 1.False. A step can be given, e.g.
FOR i ← 0 TO 10 STEP 2, and a negative step counts down.How is a
WHILEloop written in AQA pseudo-code?e.g. keep doubling
total, which starts at 1, while it is under 50- Set the variable used in the condition before the loop:
total ← 1 - Write
WHILEand the condition:WHILE total < 50 - Write the code to repeat, then close the loop:
total ← total * 2thenENDWHILE
- Set the variable used in the condition before the loop:
What is nested selection?
An
IFstatement written inside theIFbranch or theELSEbranch of anotherIFstatement, so the inner check is only reached when the outer one gives that result, e.g. only checking the password once the username is correct.When does a
WHILEloop, and when does aREPEAT … UNTILloop, become an infinite loop?A
WHILEloop never ends if its condition is always true. AREPEAT … UNTILloop never ends if its condition is never true.Why should a programmer use meaningful identifier names?
The names show what each variable, constant or subroutine stores or does, so the code is easier to understand, debug and update, e.g.
totalScorerather thanx.How is a named constant declared in AQA pseudo-code?
e.g. a constant for pi
With the keyword
CONSTANT, then the name and its value:CONSTANT PI ← 3.141How does a
DO … WHILEloop work?e.g.
DO … WHILE NotSolvedIts condition is tested at the end, so the code inside always runs at least once. It repeats while the condition is true, here while
NotSolvedis true.What is an identifier?
The name a programmer gives to a variable, a constant or a subroutine, e.g.
totalScoreorcalculatePrice.Why can't
number of itemsbe used as an identifier?Identifiers cannot contain spaces. A name such as
numberOfItemsoritemCountcould be used instead.In programming, what is sequence?
Carrying out statements one after another, in the order they are written, e.g. input a value, then calculate with it, then output the result.
How do you choose between definite (
FOR) and indefinite (WHILEorREPEAT … UNTIL) iteration?Use definite iteration when the number of repetitions is known before the loop starts, e.g. outputting each of the 10 items in an array. Use indefinite iteration when it depends on a condition, e.g. asking for a password again until the correct one is entered.