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

Year 8 - Introducing loops - For

What do I need to Learn?

I need to learn how to use simple loops in a program to repeat specific behaviour
I need to learn how to use determinite loops to repeat code a specific number of times
I use a for loop to go through the characters in a string

Knowledge Organiser

×

Lesson

Task 1 - Getting Organised - PowerPoint Click to see more

  1. Set your Learning Objectives to red.

  2. We are going to save all of our work for this topic into this PowerPoint.

  3. To download the PowerPoint by clicking on the image below


  4. Save your PowerPoint as 'Programming 1'


Task 2 - 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 condition is met. Today we are going to look at the For 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 Codeskulptor or Thonny by clicking on the Blocks button in the top right hand corner of the page.

The code should look like this:


Task 3 - Creating a For Loop Click to see more

Writing a simple For Loop

When coding we sometimes want to repeat lines of code. We could do this by writing them out again, but it is much better to use a loop to repeat them.

A for loop is a counting loop. We tell it how many tims we want it to repeat, then it counts up to that number and then stops.

We are now going to create a simple for loop that repeats 5 timesand prints out 'hello' each time it repeats.



We are now going to create a simple for loop that repeats 5 times and prints out 'hello' each time it repeats.

  • Here is the code for you:
  • for i in range(5):
         print("hello")
    1. Copy the code above into your python window.

    2. Save the file name as for_loop.

    3. Run the code.

    You should see this



    Activity 1

    1. Change Line 2 to print out something instead of 'hello'.
    2. Change the number in the loop to print out a different number of times

    Extension Activity 1

    1. Ask the user to input a number and use that value in the loop to print out a different number of times.

    In your Powerpoint put a screenshot of your code.


  • When you are finished don't forget to save your powerpoint

  • Task 4 - Counting loops Click to see more

    We are now going to look at how the for loop works. Remember it is a counting loop that runs a specific number of times.

    In python we can use the range() function to tell our loop how many times it is going to run. So if we wanted it to run 3 times we would use range(3).

    We do have to keep a count of how many times the for loop has already run, so for that we use a counter or iterator, which keeps a track of how many times the loop has already run and checks against the range value to see if it is time to stop.

    Our counting variable can be called anything we want, I have called mine i in the code above which is shore for iterator but you could call it whatever you want.

    Look at the code below and copy it into your python program and run it.

    Activity 2

    1. Change the loop so that it prints out the number range 3 to 10.

    Extension Activity 2

    1. Ask the user to input a number and use that value in the loop to print out a different range of numbers.

    In your Powerpoint put a screenshot of your code.


  • When you are finished don't forget to save your your powerpoint

  • Task 5 - Try it on Edublocks Click to see more

    Below you can see I have answered one of the extension questions using Edublocks.

    Activity 3

    1. Have a play yourself see what you can do.

    In your Powerpoint put a screenshot of your Edublocks code.


  • When you are finished don't forget to save your your powerpoint

  • Task 6 - Lesson review 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 simple loops in a program to repeat specific behaviour

    • I have a basic understanding of how I can use simple loops in a program to repeat specific behaviour with a little help from my teacher
    • I can show my teacher that I can use simple loops in a program to repeat specific behaviour without their help.
    • I can use simple loops in a program to repeat specific behaviour 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: Coding-p2

    Student_Comment_4 not found

    Task Notes/Comments - Add here Click to see more

    Comments/Notes

    Copyright © 2013 -2019 LearnITwithMrC