0% found this document useful (0 votes)
13 views27 pages

ClassVII Coding Student Handbook Chapter 02

This document covers the fundamentals of sequencing in programming, including the importance of following a specific order to achieve desired outcomes. It introduces key concepts such as loops, selection, and iteration, providing examples and activities to illustrate these principles. Additionally, it discusses common programming issues like bugs and offers exercises to reinforce learning through practical application.

Uploaded by

nb955091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views27 pages

ClassVII Coding Student Handbook Chapter 02

This document covers the fundamentals of sequencing in programming, including the importance of following a specific order to achieve desired outcomes. It introduces key concepts such as loops, selection, and iteration, providing examples and activities to illustrate these principles. Additionally, it discusses common programming issues like bugs and offers exercises to reinforce learning through practical application.

Uploaded by

nb955091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

SEQUENCING WITH BLOCK CODING

order to complete a task or to solve a


2.1 What will you learn in this problem. There are three basic building
blocks that can be used when designing
Chapter?
algorithms:
1. What is sequencing? • Sequencing
2. Why is it important to follow a
• Selection
sequence in programming?
• Iteration
3. How to reduce steps in a
sequence with loops and These building blocks help us to convert
conditional operators? any complex problem into a well-defined
solution that can be understood and
implemented by others using
programming. For example, how would
2.2 Recap of Loops
you design an algorithm for your
1. In programming, repetition of a line morning routine?
or a block of code is also known as
iteration. • Wake up
2. A loop is an algorithm which • Brush your teeth
executes a block of code multiple • Take a bath
times till the time a specified • Have breakfast
condition is met. • Go to school
3. The break statement modifies the
normal flow of execution while it In this chapter, we will learn about the
terminates the existing loop and first building block of algorithms –
continues execution of the sequencing.
statement following that loop.
A sequence is a list of activities that are
4. Whenever a program encounters a
done one after another. Sequencing
continue statement, the control
refers to the specific order in which we
skips the execution of remaining
need to perform the activities in order to
statements inside the loop for the
get the desired output.
current iteration and jumps to the
beginning of the loop for the next Designing an algorithm for How to Make
iteration. a Sandwich
5. When there is a loop inside another
loop, it is called a nested loop.

2.3 What is Sequencing?


An algorithm is a detailed step-by-step
process that needs to be followed in

11 | P a g e
Every day, we do many activities in a 2.4 Examples of Sequence,
sequence. For example, think of how you Selection and Iteration
would make a sandwich. If you had to
write down the steps for making a To understand concept of sequencing in
sandwich, would it be like the steps programming, look at the below
given below? algorithm to swap two numbers:

Step 1: Start
Step 2: READ num1, num2
Step 3: temp = num1
Step 4: num1 = num2
Step 5: num2 = temp

Step 6: PRINT num1, num2


Step 7: Stop

Over here, to reach the final output, you


need to follow the algorithm step by step.

First, Read the two numbers that needs


to be swapped. Then, assign value of
num1 to a temporary variable called
“temp”. Next, assign value of num2 to
num1. Later, assign value of “temp” to
num2. Finally, Print the values of num1
If you do these steps in any other order, and num2 which are now swapped.
would the result still be a sandwich? No!
Point to be noted over here is that the
Similarly, in programming, tasks need to steps that followed to achieve this
be done in the correct sequence to get output are in a sequence. Skipping any
the desired output. step from this sequence or altering the
sequence will lead to errors in the
In both daily tasks and coding, if we
program or generation of wrong output.
don’t put every step in the right
sequence, the result will not be what we This is how sequencing in programming
wanted. Sequencing is a foundational works.
concept in programming, and everything
Now let us understand the concept of
we learn in the future will build on this
Selection using an example.
concept.
Look at below pseudocode to check if age
entered by the user is of a senior citizen
or not. Consider that person is

12 | P a g e
considered a senior citizen if his age is follow the flow as shown in the Fig 2.1
above 60 years old. flowchart.

int age = 61;


if (age>=60)

print(“Person is a senior
citizen”);

else
print(“Person is not a senior
citizen”);

Over here, the pseudocode is trying to


check if the age defined in the program
if of a senior citizen or not.
If you follow the sequence of
pseudocode, you will see that the
program makes a “selection” of which
flow to enter depending on the age
defined in the program.
If the age is more than or equal to 60,
the program enters the if block. If the age As you can see in the flow chart the flow
is less than 60, the program enters else of the program will repeat or iterate for
block. each number from 1 to 100. For every
This is how concept of selection is single iteration it will check for the
applied in programming. condition and take the appropriate
workflow. This is how iteration works in
Moving forward, let us have a look at programming. It will repeat the block of
example of Iteration. code for multiple times till the specified
condition is achieved.
In programming, loops follow the
iteration depending on the condition.
Every loop iterates at least once if not
more.
Consider a program to print all the
natural numbers from 1 to 100. It will

13 | P a g e
2.5 What is a Bug? For example, suppose you create a boat
which is expected to sail in ocean. Now
A bug is a terminology
when the boat is ready and you try to
used to describe any
sail it in the water, you realize that there
unexpected problem in
is a small hole in the bottom on the boat
your program. Just like
from where water is seeping in. This
we learnt in the past water seeping in the boat at a slow speed
topics, we follow a sequence of activities
may create a problem for the boat in the
to complete a program. This program is long run. Thus, this hole in the bottom
expected to return a specific output. Any of the boat can be termed as a “bug” in
deviation in the expected and actual programming.
output of the program is known as a
bug.

2.6 Activity Drawing Rectangle

Let us now understand sequencing with another example.


What would be the steps to draw a rectangle of length 5 cm and height 3 cm on your
screen?

First, draw a line 5 cm in length


Then turn the cursor right by 90 degrees
Then draw a second line 3 cm in length
Then turn right by 90 degrees

Then draw a third line 5 cm in length


Then turn right by 90 degrees

Then draw a fourth line 3 cm in length

Let us now see how we can make a rectangle in Minecraft using the above steps. You
should try this exercise on Minecraft using the MakeCode editor for Minecraft, which
can be found here https://minecraft.makecode.com/

14 | P a g e
Once you complete this exercise, the final output should look like as shown in the
screenshot below:

Let us now follow below steps to get this output on our screen:

15 | P a g e
Now follow the following steps

16 | P a g e
17 | P a g e
18 | P a g e
19 | P a g e
If you complete the steps above, you should be able to create a rectangle.

Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org (https://code.org/).

2.7 Fun Activity: Chase the Apple

In this activity, we will create a game with 2 sprites, a Player sprite and an Apple sprite.
The objective of this game is to chase and catch the wandering apple and collect as
many points as possible before the time runs out. Every time the apple is caught, points
are added, and the timer is restored.
You should try creating this game on Arcade using the MakeCode editor which can be
found here https://arcade.makecode.com

First, create a new project as shown below.

20 | P a g e
Now follow the steps mentioned below to create the game.

21 | P a g e
22 | P a g e
23 | P a g e
24 | P a g e
25 | P a g e
26 | P a g e
27 | P a g e
28 | P a g e
Note: Arcade is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org (https://code.org/)

29 | P a g e
success condition of outer loop triggers
Activity the inner loop which runs and reaches
completion. This combination of loops
• Create a square of size 10 and inside loop is helpful while working with
spawn 2 sheep in it. requirements where user wants to work
• Create two squares such that they of multiple conditions simultaneously.
have a common side. Spawn 2 There is no restriction on how many
chickens in one square and 2 cows loops can be nested inside a loop.
in the other.

2.9 Apply Loops and


Conditionals with
2.8 Types of Loops sequencing

As we have studied, use of loops make Now, let us discuss the other two
our code manageable and organized. important aspects of an algorithm –
Mainly, there are three different types of selection and iteration.
loops:
Selection refers to the situation in which
the algorithm needs to make a choice
1. While Loop between two or more alternatives. It is
2. For Loop like asking questions like “Is it raining?”.
3. Nested Loop If the answer to the question is true, the
algorithm follows one path. If the answer
is false, the algorithm follows a different
While Loop path.
The While Loop can execute a set of Iteration refers to the process of doing
commands till the condition is true. the same task over and repeatedly, until
While Loops are also called conditional a certain task is complete, or a certain
loops. condition is met. The iteration can also
Once the condition is met then the loop be set to run for a specific number of
is finished. times. For example, think of a race in
which a car must go around a track five
times. The car will keep going around
For Loop the track repeatedly until it completes
For Loop is needed for iterating over a five laps. Once that is done, it will exit
sequence. A for loop executes for a the track.
specific number of times. Now let us see how we can combine all
Nested Loops the three building blocks of algorithms –
sequencing, selection, and iteration.
Any loop in program may contain
another loop inside it. When there is a In real life, complex algorithms can have
loop inside another loop, it is called as a hundreds, if not thousands, of steps in
nested loop. How it works is that first a sequence. However, often while
working on a sequence, you will notice

30 | P a g e
that certain activities in the sequence For example, in the last exercise, while
are repeated. We can reduce the number creating a rectangle, we had to turn right
of steps of the sequence by using a loop after drawing a line and we had to do so
along with certain conditions to check three times.
when the loop should stop.
Can we use a loop to reduce the number
of steps

2.10 Is there a better way to apply sequencing?

Activity: Better way to create a square

With an example, let us now understand sequencing with loops and conditionals. What
would be the steps to draw a square of side 5 cm on your screen?

Do you notice a pattern getting repeated in the steps? Let us see how we can use a loop
to reduce the steps by using the Minecraft platform.
First, create a new project called “Make Square”. Once you create your project, you
should see the editor below
At the end of this exercise, the final output should look like the one shown in the image
below:

31 | P a g e
32 | P a g e
33 | P a g e
Note: Minecraft is just one of the platforms to achieve this output. You can use many
similar platforms available online to achieve similar output like – Scratch
(https://scratch.mit.edu/) and Code.org (https://code.org/).

2.11 Activity: Distributing Birthday Sweets

In this activity, we will learn about iteration.


It is Arun’s birthday today. The entire class wishes birthday to Arun. Later, Arun takes
out the sweets from his bag and starts distributing it to the students of the class.

34 | P a g e
Take a look at flowchart in Fig 1.0 understand how Arun uses concept of iteration while
distributing birthday sweets with the class.

If you notice, there is a pattern which Arun follows while distributing sweets. He takes
the chocolates out from his bag, gives one chocolate to a student, moves to the next
student and repeats the same steps again till the sweets are distributed within all the
students.
This is an example of an iterative process. Repetition of a set of steps with a defined end
– in this case the repetition ended when all the students in the class were given
chocolates.

35 | P a g e
2.12 Quiz Time

Objective Type Questions

Question 1 What is a bug in programming?


Option 1 A feature in a program that causes it to run correctly
Option 2 A feature in a program that can predict output.
Option 3 A feature in a program that generates incorrect output.
Option 4 All the above

Question 2 What is sequencing in programming?

Option 1 A programming structure, where steps are performed in an order.


Option 2 A programming structure, that repeats itself until a condition is met.
Option 3 A feature in a program that generates incorrect output.
Option 4 All the above

Question 3 What is looping in programming?

Option 1 A programming structure, where steps are performed in an order.


Option 2 A programming structure that repeats itself until a condition is met.
Option 3 A feature in a program that generates incorrect output.
Option 4 All the above

Question 4 What is selection in programming?

Option 1 A list of instructions which are followed in a set order


Option 2 A list of instructions where there is a choice based on a condition
Option 3 A list of instructions which will loop based on a condition
Option 4 A list of instructions that will loop forever

Question 5 What is iteration in programming?

Option 1 A list of instructions which are followed in a set order


Option 2 A list of instructions where there is a choice based on a condition
Option 3 A list of instructions which will loop based on a condition
Option 4 A list of instructions that will loop forever

36 | P a g e
Standard Questions

1. Explain what an algorithm is with the help of an example.


2. Explain a bug in any program/application that you have encountered in real
life.
3. Explain if sequencing, selection and iteration can be used together? Support
your answer with a proper explanation.
4. Explain three examples where you can apply loop and conditionals to simplify
sequencing

Higher Order Thinking Skills (HOTS)

1. Write an algorithm to print cube of numbers from 1 to 10.


2. Draw a flowchart to explain the iterative process that Arun followed while
distributing birthday sweets.

Applied Project

Create a rectangle of length 5 and height 3 using a loop (repeat block) in Minecraft.

2.13 What have you learnt in this chapter?

By now you:

• Should have an understanding about the basics of algorithms.


• Should have an understanding about sequencing and its importance.
• Should know how to apply loops and conditions to simplify sequencing.

37 | P a g e

You might also like