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 IF and ELSE belong to?

Selection.

Which construct do the pseudo-code keywords FOR, WHILE and REPEAT … UNTIL belong to?

Iteration.

What is the difference between definite and indefinite iteration?

Definite (count-controlled) iteration repeats a set number of times, e.g. a FOR loop. Indefinite (condition-controlled) iteration repeats until or while a condition is met, e.g. WHILE or REPEAT … UNTIL.

What is the difference between a WHILE loop and a REPEAT … UNTIL loop?

WHILE tests its condition at the start, so the code inside may run zero times. REPEAT … UNTIL tests 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

  1. Test the first condition: IF score ≥ 80 THEN OUTPUT 'A'
  2. Add further tests: ELSE IF score ≥ 60 THEN OUTPUT 'B'
  3. Catch the rest and close: ELSE OUTPUT 'C' then ENDIF

How is a count-controlled loop written in AQA pseudo-code?

e.g. output the numbers 1 to 5

  1. Set the counter, start and end: FOR i ← 1 TO 5
  2. Put the repeated code inside: OUTPUT i
  3. Close the loop: ENDFOR

True or false? A FOR loop 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 WHILE loop written in AQA pseudo-code?

e.g. keep doubling total, which starts at 1, while it is under 50

  1. Set the variable used in the condition before the loop: total ← 1
  2. Write WHILE and the condition: WHILE total < 50
  3. Write the code to repeat, then close the loop: total ← total * 2 then ENDWHILE

What is nested selection?

An IF statement written inside the IF branch or the ELSE branch of another IF statement, 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 WHILE loop, and when does a REPEAT … UNTIL loop, become an infinite loop?

A WHILE loop never ends if its condition is always true. A REPEAT … UNTIL loop 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. totalScore rather than x.

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.141

How does a DO … WHILE loop work?

e.g. DO … WHILE NotSolved

Its condition is tested at the end, so the code inside always runs at least once. It repeats while the condition is true, here while NotSolved is true.

What is an identifier?

The name a programmer gives to a variable, a constant or a subroutine, e.g. totalScore or calculatePrice.

Why can't number of items be used as an identifier?

Identifiers cannot contain spaces. A name such as numberOfItems or itemCount could 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 (WHILE or REPEAT … 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.