Assignment, Variables, Constants & Sequences
Inputs, Outputs & Type Conversion
Condition controlled Loops
Count Controlled loops
Nested Selection and Iteration
Subroutines 1 - Procedures
Subroutines 2 - Functions
Operators and Operations
Structured Programming
Validation and verification
Good notes will help you organise and process data and information
In computer science, a loop is a programming structure that repeats a sequence of instructions until a conditional statement is False. We are going to look at the While loop.
But first...
Click on the link above to open up edublocks
See if you can make the code using the blocks below
Now copy it into into either IDLE or Thonny by clicking on the Blocks button in the top right hand corner of the page.
Let's try doing a while loop in Edublocks
Save your file as 'while_loops'
1. What is wrong with this loop that tries to count to 10? What happens when it is run? How should it be fixed?
Run the code below and see if you can figure out what is being output:
There may be several ways for a loop to quit. Using a Boolean variable to trigger the event is a way of handling that. Here's an example:
Looping until the game is over or the user wants to quit" done = False while not done: quit = input("Do you want to quit? ") if quit == "y": done = True attack = input("Does your elf attack the dragon? ") if attack == "y": print("Bad choice, you died.") done = True
This isn't perfect though, because if the user says she wants to quit, the code will still ask if she wants to attack the dragon. How could you fix this?
Lets look at the learning outcomes and decide which one best describes our current level of understanding :
Tick the one you feel is closest to your level
AQA Computer Science Tutor
Python Syntax