Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE
Responsive image

Loopy Loops

What am I Learning today?

I am learning how to use count controlled loops in a program to repeat code a specific number of times
I am learning how to use condition controlled loops to repeat code based upon a boolean expression

Knowledge Organiser

×

Lesson

Task 1 - Getting Started Click to see more

You are going to screenshot all of your work into a Powerpoint file.

To download the PowerPoint by clicking on the image below

To save your powerpoint go to:

  • File explorer
  • -> Year 9 Common Area :S
  • -> You can save here
  • -> Computer Science
  • -> Term 2
  • -> Lesson 3
  • Save the Powerpoint file: as your name


  • Complete Task 1 in your Powerpoint


  • Task 2 - Side Task - Introducing Edublocks Click to see more

    Coding loops

    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.

    The code should look like this:


  • When you are finished screenshot your code into your powerpoint

  • Task 3 - Count Controlled Loops Click to see more

    Writing a simple for loop

    A for loop is either used for repeating itself a specific number of times, we use the range() fuunction for this or for iterating through a sequence (that is either a list, a tuple, a dictionary, a set, or a string).


    Task: A simple loop

  • Open Python Thonny
  • Save your file as 'for_loops'

    Add in this comment at the top of your page

    # a for loop is a
    # count controlled loop
  • Copy the code from the image above and run it.
  • Then try the challenges below.
    1. Change the loop so it runs 10 times
    2. Get the user to enter the number of times the loop will run

  • When you are finished screenshot your code into your Learning Journal



  • You can also use a for loop to iterate through different data structures like a string or a list.
  • Look at the image below and see how it loops through all the letters of a string
  • Task: Looping through structures

  • Copy the code from the image above and run it.
  • Then try the challenges below.
    1. Get the user to enter a word and print that out one letter at a time
    2. Get the user to enter a word and print out length of the word

  • When you are finished screenshot your code into your Learning Journal



  • Task 4 - Condition Controlled Loops Click to see more

    Writing a simple while loop



    1. Create a New File
    2. Add in this comment at the top of your code #A while loop allows us to repeat our code

    3. Type in the code from the image above :
    4. Save your file as 'while_loops'



    5. When you are finished screenshot your code into your Learning Journal



    6. Let's try doing a while loop in 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.

    The code should look like this:



    Save your file as 'while_loops2'


  • When you are finished screenshot your code into your Learning Journal



  • Task 5 - Continuing our Adventure Click to see more

    Last lesson we created a simple question and some different outputs using an if statement

    We are now going to ask a question using a while loop



    Here is a copy of the current text adventure code including some while loops.

    Lets try the following tasks:

    Tick each task when you have successfully done it in the following list:

    Complete the following tasks

    Open your python file called 'My_Text_Adventure'
    Add in the while loop above
    Adapt it to suit your adventure

    Don't forget to add #comments


  • When you are finished screenshot your code into your Learning Journal


  • Task 6 - Lesson Review/Homework Click to see more


    Summing it all up

    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

    Learning Outcomes I need to learn how to use condition controlled loops to repeat code based upon a boolean expression

    • I have a basic understanding of how I can use condition controlled loops to repeat code based upon a boolean expression with a little help from my teacher
    • I can show my teacher that I can use condition controlled loops to repeat code based upon a boolean expression without their help.
    • I can use condition controlled loops to repeat code based upon a boolean expression independently and I can also explain it to others and can complete any extension tasks I am given.

    🠜 Now update your learning objectivesClick on the Assessment image



    My Notes: Text_Programming

    Student_Comment_2 not found

    Task Notes/Comments - Add here Click to see more

    Comments/Notes