# data[].attributes.attachment_link.title
2.2.1 Sequence, Selection and Iteration - Revise GCSE Computer Science

# data[].attributes.body
Use this Textbook as a reference to assist you with your assignments.

# data[].attributes.attachment_link.readable_text
We use and computer-controlled devices in all areas of our lives.

They are extremely fast, accurate and brilliant at organising large amounts of . They can also perform many tasks at the same time.

We need to organise our instructions so the computer can carry them out efficiently.

One important way that we organise instructions in a program is with a REPEAT command.

Let's think about photocopying a document 30 times.

If we had to enter each copy command separately, we'd be at the photocopier all day.

We can tell the photocopier we want to print 30 copies by filling in the number in the photocopier settings.

This instructs the printing program to repeat the copying process 30 times.

The repeat instruction goes first. We call this kind of repeat command a fixed loop as the number of repeats is fixed.

This program might look like this:

Sometimes we don't know exactly how many times we want to repeat an action or task.

We might want to repeat it UNTIL something happens.

When we are washing up, we don't wipe the sponge across the plate a set number of times. We wipe the sponge UNTIL the plate is clean. We keep checking the plate for food and when we see it is clean, we stop wiping.

Using the REPEAT UNTIL command in a computer program means we are asking the program to keep on repeating an action until a specific thing happens.

Let's say we want a robot in a game to walk across the screen and stop at the edge.

The problem is that we don't know the size of the screen it might be walking across.

We can use the REPEAT UNTIL command to make it stop when it reaches the edge of the screen, whatever the screen size is.

But how will the program know when the robot reaches the edge? Now we have a problem to solve.

We know the program will need to check if the robot has reached the edge of the screen. The program will have to ask this question.
Have you reached the edge of the screen yet?

If the answer is YES, then the robot will stop.

If the answer is NO, then the robot will carry on walking forward, while checking for the edge of the screen.

Because this type of repeat command asks the program to check the conditions it finds, we call it a .

This is what it looks like as an algorithm flowchart.

Learn more about repetition with this video from BBC Teach.

NARRATION: Repetition is a word you've probably heard before. Repetition is a word you've probably heard before. Repetition is a word you've probably heard before... Haha, sorry.

We don't always know exactly how many times we want to repeat an action, we might want to repeat it until something happens. Like shouting at your sister to come and sit down at the table for dinner over and over again until she actually turns off the TV and comes into the kitchen! You don't know at the start how many times you will need to repeat the action, you just keep on doing it until you get the result you want.

Let's say we want our little robot from earlier to walk across the screen, but we don't know how big the screen is. Maybe it's a laptop, or a TV, or a mobile phone... We could tell little robot to repeat the walk one step command until she got to the other side, then it wouldn't matter what size it was. Clever huh?

Our program would look like this: Repeat, walk forward one step until edge of the screen reached. Stop. See how tidy and efficient it is?

The big question though, is how will the program know when little robot has reached the edge of the screen? And yes, it involves a big question. Each time the robot takes a step forward the program checks if she is at the screen edge by asking a question like in this flow chart. If the answer is no, then the program carries on around the loop and little robot takes another step. If the answer is yes, then the program stops and she stops walking.

This type of loop, where the program checks something by asking a question, is called a conditional loop. The program is checking on what is happening, the conditions, and deciding whether to continue around the repeat loop or stop.

It sounds simple enough, right? But imagine trying to write the program for an online game played by thousands of people with hundreds of characters and worlds. If you had to write each line of code without using the repeat command it would take you weeks, no months, or even years! So, using repetition and loops can be a great way to save ourselves time.

So that's repetition. If you don't get it, repeat this video until you do!

We can see from looking at the conditional loop example above that adding questions to a computer program can help it solve tricky problems.

This allows them to deal with different situations and problems, running different sections of code or even separate programs for different conditions.

The use of selection in computer programs is what makes them so flexible and good at dealing with changing situations like traffic, weather and everyday life!

You are getting ready for a day out in the park and wonder whether to take your umbrella. You need to make some choices, depending on the weather.

You take a quick look out of the window. If it is raining, then you will take an umbrella. If not, then you can leave it at home.

We make these kinds of choices all the time, checking conditions and making decisions based on what we find.

We can draw a flowchart to show how this works:

call this way of organising instructions in a program selection.

The program is selecting an answer or action from several choices.

We often use program commands like IF, THEN and ELSE when we write programs that use selection.

If we wanted to program a robot to go to the park, then you could write a program like this:

Find out more about selection in computer programming with this video from BBC Teach.

# data[].attributes.attachment_link.description
Learn about repetition and selection with this KS2 primary computing guide from BBC Bitesize for years 5 and 6.

# data[].attributes.body
Online Scratch Programming

# data[].attributes.attachment_link.description
Scratch is a free programming language and online community where you can create your own interactive stories, games, and animations.

# data[].attributes.body
Use the Jotform link above to send all your work for this term to be graded.

The Objective of the course(s) is to allow you to master the skills: Drag and drop commands, formatting and incorporating speech and movement, sequence and repeat construct instructions etc ...

You can also refer to Chapter 12 in the reference Textbook for assistance.

1. April 24th: Create a program that accepts input. Using scratch, animate your name program exercise. Due 30th April.

2. May 1st: Create a program that accepts 3 variables (person, item, pet), a sequence of steps that your Avatar must complete and one type of (speech, movements). Use scratch to complete Sequencing and Sprites exercises. Due 7th May.

3. May 8th: Create a program using 1 hour of code (Infinity Play Lab, Guinea Pig Survivors, Code Combat) and implement at least one arithmetic calculation on a named variable. Due 14th May.

4. May 15th: Using Scratch, implement a program using an If then else condition, Activity 2 on page 462 under Scratch Programming in the Reference Textbook. Due 21st May

5. May 29th: To Be done in Class: Chapter 11: Short Answers and Crossword pg 402/403 and Chapter 12: Fill in the blanks, True or False and Multiple Choice pg 467. Assignments could be written or use Jotforms to upload. Deadline 29.05.24 12mn. For homework: Using Code.org implement a loop (Game Lab). Create or login to your account. Due 4th June

6. June 5th: Using Scratch, create the Ping-Pong game, screen-shot your code and upload here. Use the Ping-Pong instructions pdf listed on this page.  Due 11 June.

7. June 12th: Mock closed

8. June 19th: Using Scratch, complete the entire exercise in the "Learning to Scratch pdf". Follow the instructions from page 1 to 16. Due 20th June.

# data[].attributes.attachment_link.description
Please click the link to complete this form.

# data[].attributes.body
Careers in ICT

# data[].attributes.attachment_link.title
Top 20 In-Demand Information Technology Careers - DegreeQuery.com

# data[].attributes.attachment_link.description
We all know tech jobs are hot. You’d have to be living under a rock not to see it. Between 65 year-old grandmothers standing […]

# data[].attributes.body
Sites to complete assignments:

Hour of Code

Coding

Studio Code

Scratch Assignments

# data[].attributes.body
For the visual effect, look at this video:

https://youtu.be/r3Ti5Xp9W8A

# data[].attributes.attachment_link.readable_text
In the field of programming, Iteration Statements are helpful when we need a specific task in repetition. They're essential as they reduce hours of work to seconds. In this article, we will explore the basics of loops, with the different types and best practices.

What are Loops in Programming?

Loops, also known as iterative statements, are used when we need to execute a block of code repetitively. Loops in programming are control flow structures that enable the repeated execution of a set of instructions or code block as long as a specified condition is met. Loops are fundamental to the concept of iteration in programming, enhancing code efficiency, readability and promoting the reuse of code logic.

Types of Loops in Programming:

In programming, loops are categorized into two main types based on the control mechanism: entry-controlled loops and exit-controlled loops.

1. Entry-Controlled loops:

Below are the examples of Entry-controlled loops:

2. Exit-Controlled loops:

In Exit controlled loops the test condition is evaluated at the end of the loop body. The loop body will execute at least once, irrespective of whether the condition is true or false. Do-while Loop is an example of Exit Controlled loop.

Below are the examples of Exit-controlled loops:

A for loop in programming is a control flow structure that iterates over a sequence of elements, such as a range of numbers, items in a list, or characters in a string. The loop is entry-controlled because it determines the number of iterations before entering the loop.

The basic syntax for a for loop often includes a variable that takes on each value in the sequence, and the loop body contains the code to be executed during each iteration.

A while loop in programming is an entry-controlled control flow structure that repeatedly executes a block of code as long as a specified condition is true. The loop continues to iterate while the condition remains true, and it terminates once the condition evaluates to false.

The basic syntax for a for loop often includes a condition which is checked before each iteration and if the condition evaluates to true, the loop body containing the code gets executed otherwise the loop gets terminated.

A do-while loop in programming is an exit-controlled control flow structure that executes a block of code at least once and then repeatedly executes the block as long as a specified condition remains true. The distinctive feature of a do-while loop is that the condition is evaluated after the code block, ensuring that the block is executed at least once, even if the condition is initially false.

The basic syntax for a for loop includes a block of code followed by a condition which is checked after each iteration and if the condition evaluates to true, the next iteration takes place otherwise the loop gets terminated.

Nested loops in programming are when one loop is placed inside another. This allows for the iteration of one or more loops within the body of another loop. Each time the outer loop executes, the inner loop completes its full iteration. Nested loops are commonly employed for tasks involving multidimensional data processing, pattern printing, or handling complex data structures. Efficient use of nested loops is essential, considering potential impacts on code readability and execution time for larger datasets.

For Loop vs While Loop vs Do-While Loop in Programming :

Common mistakes to avoid in Programming:

1. Infinite Loops: Not ensuring that the loop condition will eventually become false can lead to infinite loops, causing the program to hang.

2. Off-by-One Errors: Mismanaging loop counters or conditions can lead to off-by-one errors, either skipping the first iteration or causing an extra, unintended iteration.

3. Uninitialized Variables: Forgetting to initialize loop control variables properly can result in unpredictable behavior.

4. Inefficient Nesting: Excessive or inefficient use of nested loops can lead to performance issues, especially with large datasets.

5. Modifying Loop Variable Inside the Loop: Changing the loop variable inside the loop can lead to unexpected behavior. For example, modifying the iterator variable in a for loop.

In conclusion, loops in Programming are very useful in programming as they help to repeat and automate tasks. Whether through entry-controlled loops like for and while, or exit-controlled loops like do-while, loops form the backbone of algorithmic logic, enabling the creation of robust software that can handle repetitive operations, iterate through data structures, and execute complex tasks. Mastering loop structures is fundamental for any programmer seeking to optimize code, enhance readability, and master algorithm design.

# data[].attributes.attachment_link.description
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

# data[].attributes.body
To look at a video explaining If then Else, click on the following link:

https://youtu.be/HQ3dCWjfRZ4

# data[].attributes.attachment_link.readable_text
Conditions and If Statements

You have already learned that C supports the usual logical conditions from mathematics:

You can use these conditions to perform different actions for different decisions.

C has the following conditional statements:

Use if to specify a block of code to be executed, if a specified condition istrue

Use else to specify a block of code to be executed, if the same condition isfalse

Use else if to specify a new condition to test, if the first condition isfalse

Use switch to specify many alternative blocks of code to be executed

The if Statement

Use the if statement to specify a block of code to be executed if a condition is true.

Syntax

Note that if is in lowercase letters. Uppercase letters (If or IF) will generate an error.

In the example below, we test two values to find out if 20 is greater than 18. If the condition is true, print some text:

We can also test variables:

Example

Try it Yourself "

Example explained

In the example above we use two variables, x and y, to test whether x is greater than y (using the> operator). As x is 20, and y is 18, and we know that 20 is greater than 18, we print to the screen that "x is greater than y".

# data[].attributes.attachment_link.description
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

# data[].attributes.attachment_link.readable_text
In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output. For example,

An algorithm to add two numbers:

Qualities of a Good Algorithm

Input and output should be defined precisely.

Each step in the algorithm should be clear and unambiguous.

Algorithms should be most effective among many different ways to solve a problem.

An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.

Algorithm Examples
Algorithm to add two numbers Algorithm to find the largest among three numbers Algorithm to find all the roots of the quadratic equation Algorithm to find the factorial Algorithm to check prime number Algorithm of Fibonacci series
Algorithm 1: Add two numbers entered by the user

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
        sum←num1+num2
Step 5: Display sum
Step 6: Stop

Algorithm 2: Find the largest number among three numbers

Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
           If a > c
              Display a is the largest number.
           Else
              Display c is the largest number.
        Else
           If b > c
              Display b is the largest number.
           Else
              Display c is the greatest number.
Step 5: Stop

Algorithm 3: Find Roots of a Quadratic Equation ax² + bx + c = 0

Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
         D ← b2-4ac
Step 4: If D ≥ 0
              r1 ← (-b+√D)/2a
              r2 ← (-b-√D)/2a
              Display r1 and r2 as roots.
        Else
              Calculate real part and imaginary part
              rp ← -b/2a
              ip ← √(-D)/2a
              Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop

Algorithm 4: Find the factorial of a number

Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
          factorial ← 1
          i ← 1
Step 4: Read value of n
Step 5: Repeat the steps until i = n
     5.1: factorial ← factorial*i
     5.2: i ← i+1
Step 6: Display factorial
Step 7: Stop

Algorithm 5: Check whether a number is prime or not

Step 1: Start
Step 2: Declare variables n, i, flag.
Step 3: Initialize variables
        flag ← 1
        i ← 2
Step 4: Read n from the user.
Step 5: Repeat the steps until i=(n/2)
     5.1 If remainder of n÷i equals 0
            flag ← 0
            Go to step 6
     5.2 i ← i+1
Step 6: If flag = 0
           Display n is not prime
        else
           Display n is prime
Step 7: Stop

Algorithm 6: Find the Fibonacci series till the term less than 1000

Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term ← 0 second_term ← 1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term ≤ 1000
     5.1: temp ← second_term
     5.2: second_term ← second_term + first_term
     5.3: first_term ← temp
     5.4: Display second_term
Step 6: Stop

# data[].attributes.attachment_link.description
An algorithm is a set of well-defined instructions in sequence to solve a problem. In this tutorial, we will learn what algorithms are with the help of examples.

# data[].attributes.attachment_link.title
What are Variables? Coding for Kids | Kodable