Back to 课程

Computer Science GCES AQA

0% Complete
0/0 Steps
  1. Representing Algorithms Aqa
    4 主题
  2. Efficiency Of Algorithms Aqa
    1 主题
  3. Searching Algorithms Aqa
    3 主题
  4. Sorting Algorithms Aqa
    3 主题
  5. Data Types Aqa
    1 主题
  6. Programming Concepts Aqa
    5 主题
  7. Arithmetic Relational And Boolean Operations Aqa
    1 主题
  8. Data Structures Aqa
    3 主题
  9. String Manipulation Aqa
    1 主题
  10. Random Number Generation Aqa
    1 主题
  11. Structured Programming Aqa
    2 主题
  12. Robust And Secure Programming Aqa
    4 主题
  13. Number Bases Aqa
    2 主题
  14. Converting Between Number Bases Aqa
    3 主题
  15. Units Of Information Aqa
    9 主题
  16. Hardware And Software Aqa
    4 主题
  17. Boolean Logic Aqa
    3 主题
  18. Programming Languages And Translators Aqa
    2 主题
  19. Cpu Architecture Performance And Embedded Systems Aqa
    4 主题
  20. Memory Aqa
    2 主题
  21. Secondary Storage Aqa
    3 主题
  22. Fundamentals Of Computer Networks Aqa
    8 主题
  23. Fundamentals Of Cyber Security Aqa
    1 主题
  24. Methods Of Preventing Cyber Security Threats Aqa
    1 主题
  25. Relational Databases Aqa
    2 主题
  26. Ethical Legal And Environmental Impacts Aqa
    2 主题
课 Progress
0% Complete

Exam code:8525

Iteration

What is iteration?

  • Iteration is repeating a line or a block of code using a loop

  • Iteration can be:

    • Definite (count controlled) – this is when the code is repeated a fixed number of times (e.g. using a for loop)

xp66-srn-for-loop-pseudocode-computer-science-revision-notes
  • Indefinite (condition controlled) – this is when the code is repeated until a condition is met (e.g. using a while loop or a do while loop)

while-loop-password-pseudocode-computer-science-revision-notes

Examples

Iteration

Pseudocode

Python

FOR loop

(Definite Iteration)

FOR x ← 0 to 9

OUTPUT("Hello")

ENDFOR

for x in range(10):

print("Hello")

This will print the word “Hello” 10 times (0-9 inclusive)

FOR x ← 2 to 10 step 2

OUTPUT(x)

ENDFOR

for x in range(2,12,2):

print(x)

# Python range function excludes end value

This will print the even numbers from 2 to 10 inclusive

for x ← 10 to 0 step -1

OUTPUT(x)

ENDFOR

for x in range(10,-1,-1):

print(x)

# Python range function excludes end value

This will print the numbers from 10 to 0 inclusive

WHILE loop

(Indefinite Iteration)

while colour != "Red"

colour ← input("New colour")

ENDWHILE

while colour != "Red":

colour = input("New colour")

 

This will loop until the user inputs the colour “Red”. Check condition is carried out before entering loop

DO WHILE loop

(Indefinite Iteration)

DO

colour ← input("New colour")

UNTIL answer == "Red"

# Not used in Python

 

This will loop until the user inputs the colour “Red”. Loop iterates once before a check is carried out

How to identify programming constructs

  • You can identify which programming constructs are used by looking at certain keywords

  • The keywords if, elseif, else, endif indicate that the construct is selection

  • The keywords for, while, do indicate that the construct is iteration

  • If none of these keywords are used, this is a good indication that the construct is sequence

Worked Example

Tick (✓) one box in each row to identify whether each programming construct has or has not been used in the program [3]

total ← 0

for i ← 1 to 5

num ← USERINPUT

total ← total + num

next i

print(total)

A table with three rows and three columns. The first column lists "Sequence," "Selection," "Iteration." The other columns are "Has been used" and "Has not been used."

How to answer this question

  • Always look for keywords first, if you find any then that construct must have been used

  • Sequence must always be used if the program works

Answer

Table with three rows labeled "Sequence," "Selection," and "Iteration." Columns indicate use, with green showing "Has been used" and white for "Has not been used."

Nested Iteration

What is nested iteration?

  • Nested means to be ‘stored inside the other

  • An example of nested iteration is one loop inside of another loop

  • It is worth noting that selection can be nested as well

Examples of nested programming

Prgm1_Iteration
Prgm2_Iteration

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注