0% found this document useful (0 votes)
187 views84 pages

To Coding: Grade Vi Teacher Handbook

This document is a teacher handbook for introducing coding concepts to students in Grade 6. It includes acknowledgments, an introduction about the purpose of teaching coding in schools, and a table of contents that lists 4 chapters which will cover ethical practices in coding, algorithms using block coding, variables using block coding, and control with conditionals. It also provides online resources for students to use, such as Minecraft Education Edition and Microsoft MakeCode. The goal of the handbook is to help students acquire early coding skills to build a foundation for future careers.

Uploaded by

manan
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)
187 views84 pages

To Coding: Grade Vi Teacher Handbook

This document is a teacher handbook for introducing coding concepts to students in Grade 6. It includes acknowledgments, an introduction about the purpose of teaching coding in schools, and a table of contents that lists 4 chapters which will cover ethical practices in coding, algorithms using block coding, variables using block coding, and control with conditionals. It also provides online resources for students to use, such as Minecraft Education Edition and Microsoft MakeCode. The goal of the handbook is to help students acquire early coding skills to build a foundation for future careers.

Uploaded by

manan
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/ 84

INTRODUCTION

TO CODING
GRADE VI
Teacher Handbook

Version 1.0
INTRODUCTION
TO CODING
GRADE VI
Teacher Handbook
ACKNOWLEDGEMENT

Patrons
• Sh. Ramesh Pokhriyal 'Nishank', Minister of Human Resource Development,
Government of India
• Sh. Dhotre Sanjay Shamrao, Minister of State for Human Resource
Development, Government of India
• Ms. Anita Karwal, IAS, Secretary, Department of School Education and Literacy,
Ministry Human Resource Development, Government of India Advisory

Editorial and Creative Inputs


• Mr. Manuj Ahuja, IAS, Chairperson, Central Board of Secondary Education

Guidance and Support


• Dr. Biswajit Saha, Director (Skill Education & Training), Central Board of
Secondary Education
• Dr. Joseph Emmanuel, Director (Academics), Central Board of Secondary
Education
• Sh. Navtez Bal, Executive Director, Public Sector, Microsoft Corporation India
Pvt. Ltd.
• Sh. Omjiwan Gupta, Director Education, Microsoft Corporation India Pvt. Ltd.
• Dr. Vinnie Jauhari, Director Education Advocacy, Microsoft Corporation India
Pvt. Ltd.
• Ms. Navdeep Kaur Kular, Education Program Manager, Allegis Services India

Value adder, Curator and Co-Ordinator


• Sh. Ravinder Pal Singh, Joint Secretary, Department of Skill Education, Central
Board of Secondary Education
ABOUT THE HANDBOOK

Coding is a creative activity that students from any discipline can engage in. It helps to
build computational thinking, develop problem solving skills, improve critical thinking
and exposure to real life situations to solve problems in various realms.

Therefore, CBSE is introducing ‘Coding’ as a skill module of 12 hours duration in classes


VI-VIII from the Session 2021-2022 onwards. The idea is also to simplify the coding
learning experience by nurturing design thinking, logical flow of ideas and ap ply this
across the disciplines. The foundations laid in the early years will help the students to
build the competencies in the area of AI, data sciences and other disciplines.

CBSE acknowledges the initiative by Microsoft India in developing this coding handbook
for class VI teachers. This handbook introduces concepts of coding and computational
thinking using real life examples and block coding with open source MakeCode platform.
It uses gamified learning approach to make learning experience more engaging. The
book is intuitive with practical examples of theoretical concepts and applied exercises.
There are mini projects that students can work on. Additionally, the handbook also
focuses on creating exposure to ethics of coding and promotes empathy among students
by activities curated to demonstrate empathy and sensitivity.

The purpose of the book is to enable the future workforce to acquire coding skills early
in their educational phase and build a solid foundation to be industry ready.
RESOURCES FOR STUDENTS

Minecraft education edition


Minecraft education edition is a game-based learning platform that promotes creativity,
collaboration, and problem-solving in an immersive digital environment. This platform
provides a fun way of learning coding and design thinking concepts. Visit
https://education.minecraft.net/ for more details.

MakeCode
Microsoft MakeCode is a free, open source platform for creating engaging computer
science learning experiences that support a progression path into real-world
programming. It brings programming to life for all students with fun projects, immediate
results, and includes both block and text editors for learners at different levels. Visit
https://www.microsoft.com/en-us/makecode for more details.

GitHub
GitHub is a storehouse where you can manage and collaborate on your code. It helps to
maintain different versions of the code easily. GitHub Student Developer Pack gives
students free access to the best developer, web development, gaming and many other
tools at no cost enabling practical learning.
Sign up for the GitHub Student developer pack here
https://education.github.com/discount_requests/student_application?utm_source=2
021-06-11-cbse
TABLE OF CONTENTS
Table of Contents ........................................................................................... I
Ethical practices in coding ...............................................................................1
Introduction to Coding ....................................................................................2
1.1 Lesson Structure ................................................................................2
1.2 Lesson Plan .......................................................................................2
1.2.1 Teacher’s Notes .............................................................................2
1.3 What will you learn in this chapter? .......................................................3
1.4 How do traffic lights work?....................................................................3
1.5 Where else do we see applications of coding?............................................3
1.6 What exactly is coding? ........................................................................3
1.7 What is a programming language?..........................................................4
1.8 Quiz Time ..........................................................................................5
1.9 What did you learn in this chapter? ........................................................5
Algorithms With Block Coding ..........................................................................6
2.1 Lesson Structure ................................................................................6
2.2 Lesson Plan .......................................................................................6
2.2.1 Teacher’s Notes .............................................................................7
2.3 What will you learn in this chapter? .......................................................8
2.4 Searching for a word in the dictionary.....................................................8
2.5 Flowcharts .........................................................................................8
2.5.1 What is a Flowchart?......................................................................8
2.5.2 Symbols used in a flowchart ............................................................9
2.5.3 Benefits of using a flowchart............................................................9
2.6 Activity: Profit and loss with flowcharts ................................................. 10
2.7 What is a Pseudocode? ....................................................................... 10
2.8 Activity: Profit and loss with pseudocode ............................................... 10
2.9 Getting started with block coding ......................................................... 11
2.10 Quiz time ...................................................................................... 14
2.11 What did you learn in this chapter? ................................................... 19

I
................................................................................................................. 20
Variables using block coding .......................................................................... 20
3.1 Lesson Structure .............................................................................. 20
3.2 Lesson Plan ..................................................................................... 20
3.2.1 Teacher’s Notes ........................................................................... 20
3.3 What will you learn in this chapter? ..................................................... 21
3.4 What are variables? ........................................................................... 21
3.5 Naming variables .............................................................................. 21
3.6 Data types in variables....................................................................... 21
3.7 Performing Operations on Variables...................................................... 24
3.8 Activity: Addition operation using block coding ....................................... 25
3.9 Quiz time......................................................................................... 32
3.10 What did you learn in this chapter? ................................................... 35
Control with conditionals............................................................................... 36
4.1 Lesson Structure .............................................................................. 36
4.2 Lesson Plan ..................................................................................... 36
4.2.1 Teacher’s Notes ........................................................................... 37
4.3 What will you learn in this chapter? ..................................................... 38
4.4 Arranging blocks............................................................................... 38
4.5 And operator .................................................................................... 38
4.6 OR Operator..................................................................................... 39
4.7 NOT Operator................................................................................... 39
4.8 Combining logical operators ................................................................ 40
4.9 Quiz time......................................................................................... 41
4.10 Relational operators........................................................................ 42
4.11 Activity: Are you a teen? .................................................................. 42
4.12 Activity: Dynamic backgrounds......................................................... 42
4.13 Nested Conditional Statements ......................................................... 48
4.14 Activity: The remainder problem........................................................ 48
4.15 Quiz time ...................................................................................... 52
4.16 What did you learn in this chapter? ................................................... 55

II
Loops using block coding............................................................................... 56
5.1 Lesson Structure .............................................................................. 56
5.2 Lesson Plan ..................................................................................... 56
5.2.1 Teacher’s Notes ........................................................................... 56
5.3 What will you learn in this chapter? ..................................................... 57
5.4 Introduction to loops ......................................................................... 57
5.5 Increment Loops ............................................................................... 57
5.6 Different types of loops....................................................................... 58
5.7 Activity: Building a music player .......................................................... 61
5.8 Entry Criteria ................................................................................... 64
5.9 Exit Criteria ..................................................................................... 64
5.10 Break Statement ............................................................................ 64
5.11 Continue Statement ........................................................................ 65
5.12 Activity: A tale of two villages............................................................ 66
5.13 Quiz time ...................................................................................... 71
5.14 What did you learn in this chapter? ................................................... 74
References .................................................................................................. 75

III
Ethical practices in coding

ETHICAL PRACTICES IN CODING


As you build capabilities around coding, you will be equipped to build software on your
own, which will have an impact on society in general. So, it is very important to adhere
to ethical practices while building your own code. Below are some practices you must
remember as you keep learning to code.

Contribute to society and human wellbeing

• You must limit negative results of software, including dangers to safety, health,
personal security, and privacy
• Do consider the aftereffects of the software. Ensure your Code respects diversity
and is utilized responsibly with social issues in mind
• In addition to this, promote environmental sustainability both locally and globally
Avoid harm to others

• Your code should not cause physical or mental injury, unjustified destruction to
property or information
• Avoid unjustified damage to reputation and environment

1|Page
Introduction to Coding

INTRODUCTION TO CODING

1.1 Lesson Structure


1. Understanding the concept of coding
2. Real-world examples of coding
3. Practice challenges

1.2 Lesson Plan


Sub-Topics Number of Method
Periods
How do Traffic Lights Work? 1 Theory
Where else do we see applications of Practical
coding?
What exactly is coding? Practical
Quiz Time 1 Practical

1.2.1 Teacher’s Notes


Discuss: What are examples of coding in real life?
The teacher should introduce coding and its applications to students. The teacher can
explain it using relatable examples to students. They can also ask the students to come
up with such examples to encourage critical thinking.
Discuss: Providing some examples of programming languages that are used in our day
to day life

2|Page
Introduction to Coding
1.3 What will you learn in sensors and maximizes efficiency by
this chapter? only functioning when traffic is present.

1.5 Where else do we see


Do you want to know what code is? How
is code applied in real life, and how does applications of coding?
it impact our day-to-day activities?
Welcome to the introductory section on Most of us knowingly or unknowingly
coding. engage with programming, be it inside
Here you will learn: our homes or outside. Coding, in the
modern world, can be seen on the
• Real world application of coding streets, at the schools, at the local
• How coding impacts our daily lives grocery stores, etc.
• What exactly is coding in context Some of the practical examples of coding
of computer science
in the real world are:

1 Interaction with bar-code


scanners at shopping store
1.4 How do traffic lights 2 Automatic control of traffic using
work? traffic lights
3 Booking movie, bus, train, flight
tickets online
Have you ever wondered 4 Printers
how traffic signals 5 Computer software we use like
function? The lights cycle web browser, Word etc.
through green, yellow, 6 Video games and animations for
and red at regular entertainment
intervals to control road
intersections' traffic flow. They prevent
accidents and help to avoid congestion 1.6 What exactly is coding?
on the roads.
However, how do the traffic lights Coding, also referred to as
change automatically? programming, is creating instructions
that can be executed on a computer to
Few lines of code running in the
perform a specific task or achieve a
background drive the traffic lights. At
particular result.
regular intervals, the code changes the
traffic signals to show different colors. Coding is just like solving a math
Sometimes it is even smarter, where the problem. There may be many ways to
code detects congestion based on solve a problem. Similarly, there could
be more than one way to write

3|Page
Introduction to Coding
code for the same task. Just like solving
any other problem, some coding
approaches are more efficient than
others.

Think you are playing a video on your


smartphone. Your phone is like a
computer that needs to be instructed on
what to be done. The app playing the
video provides this instruction. This
video-playing app is an example of
coding. But how does the app
communicate the instructions to the
phone? It does via a programming
language. In the next section, we will get
to know more about programming
languages.

1.7 What is a programming


Some of the most frequently used
language?
ones are:
• Python
Think about how we communicate with • Java
people around us? Language is our • JavaScript
primary means of communication for all • C#
human interactions. Similarly, we can • R
interact with computers via a language • C++
that computers understand. This • C
language is called a programming • F#
language. Using programming • COBOL
languages, we can provide instructions
to a computer to perform a set of time. Every programming language has
activities. These sets of instructions are its own syntax. But all programming
also called programs. Like any other languages have one common thing: they
language that has grammar, are eventually converted into a language
programming languages have syntax. that the computer will understand.
Syntax is a set of rules that we need to
follow when we write a computer Throughout this chapter, we will learn
program. about different programming techniques
and how to apply them. Now, that we
There are hundreds of programming know a little bit about coding and its
languages used around the world. And applications, let us try to do some
new ones are getting developed all the exercises.

4|Page
Introduction to Coding

1.8 Quiz Time

Question 1 For a given problem, there is always only one way to write a program

Option 1 True
Option 2 False
Answer: Option 2

Question 2 Pin authentication for ATM card transaction is an example of


programming
Option 1 True
Option 2 False
Answer: Option 1

Question 3 Code is a set of instructions that can be executed on a computer to


perform a specific task
Option 1 True
Option 2 False
Answer: Option 1

Question 4 Which among the below are examples of programming in real life?

Option 1 Robots
Option 2 Computer Games
Option 3 Self-drive cars
Option 4 All the above
Answer: Option 4

Question 5 Which among the below is not an example of programming language?

Option 1 Python
Option 2 English
Option 3 JavaScript
Answer: Option

1.9 What did you learn in this chapter?


So, we are at the end of the introductory chapter for coding. By now, you should
understand:

• How coding is being utilized in everyday life to perform complex tasks in an easy
manner
• What are the real-life applications of coding?
• What is exactly meant by the term coding in context of computer science?
• Now you know names of some of the most popular programming languages

5|Page
Algorithms With Block Coding

ALGORITHMS WITH BLOCK


CODING
2.1 Lesson Structure
1. Searching for a word in a dictionary
2. Flowchart
a. What is a Flowchart?
b. Symbols used created a Flowchart
3. Activity – Profit and Loss using Flowcharts
4. What is a Pseudocode
5. Activity – Profit and Loss using pseudocode
6. Activity-Are you a teen?
7. Getting Started with Block Coding
8. Practice Assignment

2.2 Lesson Plan


Sub-Topics Number of Periods Method

Searching for a word in a dictionary 3 Practical

What is a Flowchart Theory

Symbols used to create a Flowchart Practical

Activity – Profit and Loss using Practical


Flowcharts

What is a Pseudocode Theory

Activity – Profit and Loss using Practical


pseudocode

Getting Started with Block Coding Practical

Practice Assignment 1 Practical

6|Page
Algorithms With Block Coding

2.2.1 Teacher’s Notes


Discuss: What is a flowchart?
The teacher should introduce flowcharts to the students by using real-life examples like
those mentioned in the curriculum. They can also ask the students to come up with such
examples to encourage critical thinking.
Discuss: What is a Pseudocode?

The teacher should introduce pseudocode to the students by using real-life examples like
those mentioned in the curriculum. They should make sure that the children are not
confused with these terms and explain the pseudo code to the students to improve their
conceptual understanding
Activity: Place students in groups of three or four and guide them through the
exercises
For the exercise section, the teacher should make sure that the children are comfortable
with the Make Code platform and they have it working on their computers. The practice
challenges can be solved in several ways and do not have a definite answer.

Assignment: Allow students to perform at least one practice exercise on their own
The teacher should encourage students to come up with unique solutions to the challenges
to test their creativity and understanding of the subject.

7|Page
Algorithms With Block Coding
In other words, Mukesh needs to follow
2.3 What will you learn in a set of steps to complete the task of
this chapter? finding the meaning of a word.
Similarly, before writing a program code
Now that we already have a fair for a given problem in computer science,
understanding of coding applications in it is essential to devise a set of steps to
real life, let us understand how to solve be followed to solve the problem
a coding problem in detail. By the end of successfully. This set of steps is called
this chapter, you will learn: an algorithm.

Thus, in computer science, an algorithm


is defined as the step-by-step plan to
• What does the term algorithm solve the problem for a given problem
mean?
statement.
• What is a flowchart?
• Applications of flowchart
• Get introduced to pseudocode 2.5 Flowcharts
2.5.1 What is a Flowchart?
2.4 Searching for a word in
the dictionary A flowchart is a diagrammatic
representation of the step-by-step plan
While reading a book in a school library, to be followed for solving a task/problem
Mukesh comes across a word say 'proxy' statement.
whose meaning he does not know. So
This diagrammatic representation is
how does he find out the meaning of this
made up of shapes like boxes,
word? diamonds, parallelograms, circles,
The simple answer to this is that ellipses connected by arrows. Each
Mukesh searches for the meaning of the shape acts as a step in the solution, and
word 'proxy' in a dictionary. However, the arrows represent the direction of
there are many words in a dictionary. So flow among the steps.
how does he find that word 'proxy' in the
dictionary?
To achieve this, he first needs to find the
dictionary section with the first letter of
the word, which in this case is 'p.' Then,
within the list of words starting the first
letter 'p', he needs to find the section
having the second letter of the word 'r'.
He needs to do this operation again with
the third, fourth & fifth letters until he
finally reaches the word 'proxy' in the
dictionary & then finds its meaning.

8|Page
Algorithms With Block Coding
2.5.2 Symbols used in a flowchart

2.5.3 Benefits of using a flowchart

Some of the benefits of using a flowchart


are:
1. It helps to explain your approach
towards solving a problem
2. The flowchart helps in bringing in
visual clarity to a problem, so it
helps in practical problem solving
3. Once you build a flowchart, this
remains as documentation of the
code you are about to build. If you
need to come back and
understand the code, you can
refer to the flowchart.

9|Page
Algorithms With Block Coding
• The focus is mainly on including all
the essential steps to solve the
2.6 Activity: Profit and loss
problem. Thus, the solution tends to
with flowcharts be comprehensive
• Reviewers can quickly review the
Shown in the image is a flowchart that pseudocode & verify if the steps will
takes two inputs, namely cost price and generate the desired outcome
selling price. It then calculates profit or • While writing pseudocode, you can
loss depending on the values and prints focus on all possible scenarios. So,
the same. this helps you understand the
potential problems that might come
up later
• Since you are not worried about
coding syntax, you can concentrate
on the actual problem
• Writing pseudocode will help writing
your code much easier
• Works as documentation of the code.
So even a layman with no coding
knowledge can refer to the
pseudocode

2.8 Activity: Profit and loss


with pseudocode

Now that we have a fair understanding


of flowcharts and pseudocode, let us try
to implement the same profit and loss
problem using pseudocode.

2.7 What is a Pseudocode?

In computer science, pseudocode is


used to describe the steps followed in an
algorithm via simple human-
comprehensible language. Thus, it has
no syntax of any programming language
and can be understood by a layman. The
advantages of representing the solution
as pseudocode are multifold:

10 | P a g e
Algorithms With Block Coding
The different categories of blocks will be
explored in the upcoming chapters.
Program starts
Note: Minecraft is just one of the
Read Cost Price (CP) platforms for block coding. You can use
many similar platforms available online
Read Selling Price (SP)
for block coding like – Scratch
If (SP > CP) then (https://scratch.mit.edu/), Code.org
(https://code.org/) etc.
Profit = SP – CP
We will now start a simple block coding
Print Profit
exercise on Minecraft platform.
Else
Open the URL
Loss = CP – SP https://arcade.makecode.com in your
Print Loss favorite web browser.

Program ends

2.9 Getting started with


block coding

Microsoft MakeCode is a framework for


creating interactive and engaging
programming experiences for those new
to the world of programming.
The main objective of MakeCode is to
bring programming to the forefront in a
way that is more alluring and friendly.
To achieve this, MakeCode utilizes the
blocks programming model to let those
who are new to the world of
programming and learn coding concepts
easily.

MakeCode Arcade is one of the platforms


to perform block-based programming.
Using arcade, solution to a problem
statement can be implemented using
various categories of blocks and the
results can be seen side by side on the
same screen.

11 | P a g e
Algorithms With Block Coding

12 | P a g e
Algorithms With Block Coding

Congratulations, you have created your first block code program! Now let us do a quiz.

13 | P a g e
Algorithms With Block Coding
2.10 Quiz time
Objective type questions

1. Select a word from column A and place it in a cell on column B such that its
definition matches in cells of column C

A B C
Writing steps involved to
solve a problem in a
Algorithm
human-understandable
language

Block based coding


Flowchart
platform

Define step by step plan


Pseudo Code to solve a problem
statement

Solution to a problem
Arcade
presented as a diagram

Answer:

A B C
Pseudo Code Writing steps involved to
solve a problem in a
Algorithm
human-understandable
language

Arcade
Block based coding
Flowchart
platform

Algorithm Define step by step plan


Pseudo Code to solve a problem
statement

Flowchart
Solution to a problem
Arcade
presented as a diagram

14 | P a g e
Algorithms With Block Coding

Below is a flowchart to calculate profit and loss. Answer questions 2 to 4 based on the
flowchart.

Question 2 Jyoti owns a toy shop. She bought a toy for Rs 325 and sold it for Rs.
375. Which one from the below is correct?
Option 1 She made a loss of Rs. 50
Option 2 She made a profit of Rs. 50
Answer: Option 2

Question 3 Raju buys a pen for Rs 15, and after some time, he sells it for Rs 10.
Which one from the below is correct?
Option 1 He made a loss of Rs. 5
Option 2 He made a profit of Rs. 5
Answer: Option 1

Question 4 Ram buys a table for Rs 500, he sells it for Rs 550. Which one from
the below is correct?
Option 1 He made a loss of Rs. 50
Option 2 He made a profit of Rs. 50
Answer: Option 2

15 | P a g e
Algorithms With Block Coding

Question 5 Which of the following is not an advantage of a flowchart?

Option 1 Efficient coding


Option 2 Systematic testing
Option 3 Improper documentation
Option 4 Better communication
Answer: Option 3
Question 6 The following box denotes.

Option 1 Initialization
Option 2 Decision
Option 3 Input / Output
Option 4 Connectors
Answer: Option 2

Question 7 What is a flowchart?

Option 1 A specific programming language


Option 2 A text-based way of designing an algorithm
Option 3 A bullet point list of instructions
Option 4 A diagram that represents a set of instructions
Answer: Option 4

Question 8 What shape represents the start and end of a flowchart?

Option 1 Square
Option 2 Diamond
Option 3 Oval
Option 4 Circle
Answer: Option 3

Short Answer questions


1. What is a pseudocode?
2. What are the benefits of using flowcharts?
3. What is a flowchart?

16 | P a g e
Algorithms With Block Coding

Higher Order Thinking Skills (HOTS)

1. Below is a flowchart on how to calculate if a number is even or odd. Write the


corresponding pseudocode for the problem.

Note: Modulus operator (%) is used to find the remainder of two number.
Teacher’s Note: The teacher should explain to the students the above flowchart to
understand it and write the corresponding pseudocode. The teacher should
encourage the students to do the problem on their own.
2. The below pseudocode prints "Above average marks" if the average marks in three
subjects are greater than 75. If average marks are less than or equal to 75, then
it prints "Below average marks." Draw the corresponding flowchart for the
problem.

17 | P a g e
Algorithms With Block Coding

Program starts

Read marks for subject SubA


Read marks for subject SubB

Read marks for subject SubC

Calculate AverageMarks = (SubA + SubB + SubC)/3

Print AverageMarks

If (AverageMarks > 75)

Print (“Above Average Marks”)


Else

Print (“Below Average Marks”)

Program ends

Teacher’s Note: The teacher should explain to the students the above pseudocode
to understand it and write the corresponding flowchart. The teacher should
encourage the students to do the problem on their own.

Applied Project
Create a flowchart based on your normal school day. Here are some guidelines:
Getting ready for school

• Look at your timetable and pack your school bag


• If PE is there packing your PE uniform and shoes
At school

• Attend the morning session with subjects Math, English and science
• A decision on what to play during recess
After reaching home
• Have snacks
• Depending on the day, choose the class you have to attend.
• Monday-Karate, Tuesday-Math Class, Wednesday and Thursday Free day,
Friday-Karate

Teacher’s Note: The teacher should explain to the students the project to understand it
and write the corresponding flowchart for their daily routine. The teacher should
encourage the students to do the problem on their own. The flowcharts will be different
for all the students.

18 | P a g e
Algorithms With Block Coding
2.11 What did you learn in this chapter?
• By now you should have a basic understanding about algorithms, flowchart
& pseudocode
• You have also practiced following a step by step approach to solve a problem
using block-based programming
• You got oriented to MakeCode platform which we will use throughout the
course

19 | P a g e
Variables using block coding

VARIABLES USING BLOCK CODING

3.1 Lesson Structure


1. What are Variables?
2. Naming Variables
3. Data Types in Variables
4. Performing operations on Variables
5. Assignment

3.2 Lesson Plan


Sub-Topics Number of Method
Periods
What are Variables 2 Theory
Naming Variables Theory

Data Types in Variables Practical


Performing Operations on Practical
Variables
Practice Assignment 2 Practical

3.2.1 Teacher’s Notes


Discuss: What is a Variable?
The teacher should introduce variable to the students by using real-life examples. They
can also ask the students to come up with such examples to encourage critical thinking.
Discuss: Data Types and Operations that can be performed on those data types.

20 | P a g e
Variables using block coding
3.3 What will you learn in variables uniquely, user needs to
this chapter? allocate them a unique name. This name
acts as an identifier for that variable. In
programming, a user is not allowed to
• What are variables? use the same name of a variable more
• How to name variables? than once.
• Commonly used data types
• Performing operations on variables Naming variables make it to easier to call
them while performing operations. The
name of a variable also suggests what
3.4 What are variables? information the variable contains.
You can refer to the example before for
In programming, variable is a packet in better understanding about variables:
which we can store data. These packets If variable named as "a" is equal to 2 and
can be named and referenced and can be variable named as "b" is equal to 2,
used to perform various operations. To performing add operation on "a" and "b"
perform a mathematical operation, you
is going to result into an output as "4".
can declare two variables and perform
the operation on them.
3.6 Data types in variables
Scope of a variable refers to the part of
the code where the variable can be used.
The scope or accessibility of the Variables are the values that are acted
variables defined in a program depends upon. Every value needs to be assigned
on where you have declared it in each to a specific data type to make the
program. Any defined variable cannot be variable more readable by a computer.
accessed beyond its scope. Data type identifies what the type of data
that the declared variable can hold is.
Thus, it indirectly helps the computer to
3.5 Naming variables understand what operations need to be
performed on those variables. The

As we have understood till now,


variables are basically like nouns in a declaration of a variable in a program
programming language. Every variable
in a program is unique. To identify these

21 | P a g e
Variables using block coding
contains two components – the name of language, the syntax to declare floating-
the variable and its type. point variable changes.

Let us now understand what are the


common data types that we can use in
Example of declaring a floating-point
programming:
number variable:
• Integer
float a = 1.1;
• Floating-point number
• Character There is another type of floating-point
• String number known as a "double" data type,
• Boolean which is used to store even bigger
Integer Data Type values.

Integer data type variables store integer


values only. They store whole numbers
which have zero, positive and negative
Example of a double value:
values but not decimal values. Multiple
programming languages support double a = 8.999999999 *
different syntax to declare an Integer 7.66666666666;
variable. If a user tries to create an
integer variable and assign it a non- Character Data Type
integer value, the program returns an
error. Character type variables are used to
store character values. Syntax of
Example of declaring an Integer declaring a character variable is specific
variable: to the programming language that you
are using. If a user tries to create a
int a = 2; character variable and assign it with a
non-character value, the program will
Variables of the integer data type are throw an error. The character data type
only capable of holding single values. is the smallest data type in
These variables are not capable of programming.
holding a long list of values.
Example of declaring a character
variable:
Floating Point Number Data Type
char a = ‘w’;
Floating-point numbers are used to
store decimal values. They hold real Any character values can be declared as
numbers with decimal values. a char variable.
Depending on the programming
String Data Type
Example of declaring a String
variable: To extend the character data type, a user
may have a requirement to store and
String a = “I am a String Variable”; perform an operation on a sequence of
characters. In such cases, the String

22 | P a g e
Variables using block coding
data type is present to fit the gap. The z = int(7)
String data type stores value in a
a = float(7)
sequence of characters i.e. in String
format. y will be saved as ‘7’
Any string value can be declared as a z will be saved as 7
string variable.
a will be saved as 7.0
Boolean Data Type
Let us now apply different data types in
There is a subtype of Integer Data Type a pseudocode. We will first declare
called "Boolean Data Type", which stores different types of variables, followed by
values in Boolean type only i.e. "true" or assigning them to appropriate values.
"false". Users can choose between the
data types for variables as per program Function Main
needs and assign variables an Declare
appropriate data type.
----------------------------------------------------------
Boolean is a subtype of integer data
Declare Integer i
type. It stores true and false where true
means non-zero and false means zero. Declare Float f

Any Boolean variable holding Boolean Declare Char c


value can be declared as Boolean. Declare String s
Declare Boolean b
Example of declaring a Boolean
Assign
variable:
-----------------------------------------------------
bool a = true;
Assign i = 1234567890

Note: In some programming languages Assign f = 1.234


like python, there is no command to Assign c = ‘c’
declare variables. A variable is created
the moment you first assign a value to it. Assign s = "string"
Assign b = true
Example of declaring variables in Use
python
------------------------------------------------------
a=5
Output "Integer i = " & i
b = “Hello”
Output "Float f = " & f
Output "Char c = " & c
Output "String s = " & s
If you want to specify the data type of
Output "Boolean b = " & b
variable this can be done using casting.
End
Example: y = str(7)

23 | P a g e
Variables using block coding
Finally, we will use the variables by Arithmetic Operations
outputting their values.

The output from the above pseudocode


will be like below.

Int i = 1234567890
Float f = 1.234
Char c = c
String s = string
Boolean b = true

An arithmetic operation combines two or


Note: The syntax is different for different more numeric expressions using the
Arithmetic Operators to form a resulting
data types in other programming
numeric expression. The basic operators
languages.
for performing arithmetic are the same
In python string variables can be in many computer languages:
declared either by single quotes or
• Addition
double quotes or triple quotes.
• Subtraction
Below are some rules for naming a • Multiplication
variable in python: • Division
• A variable name cannot start with • Modulus (Remainder)
a number, it must start with an Assignment operators
alphabet or the underscore (_)
sign Assignment operators are used to assign
• Variable name is case sensitive values to variables
Sum and sum are different Different assignment operators are
variables shown below:
• A variable can only contain alpha
numeric characters and • “=”: This operator is used to
underscore assign the value on the right to
the left variable.
Example: a=50
3.7 Performing Operations on
• “+=”: This operator assigns the
Variables result to the variable on the left
after adding the current value of
After declaring the data types in the variable on left to the value on
programming, now let us move ahead the right.
and understand what operations we can Example: x += y
perform on the data types and how do It can also be written as x = x + y
we perform these operations: • “-=”: This operator assigns the
result to the variable on the left
after subtracting the value of the

24 | P a g e
Variables using block coding
variable on right from the current Example: A=8
value on the left.
B=A--
Example: : x -= y
It can also be written as x = x - y The output of B will be 7 (A-1)
• “*=”: This operator assigns the
result to the variable on the left A-- has the same meaning as A=A-1
after multiplying the current
value of the variable on left to the 3.8 Activity: Addition
value on the right. operation using block
Example: : x *= y
coding
It can also be written as x = x * y
• “/=”: This operator assigns the
result to the variable on the left An addition arithmetic operation is used
after dividing the current value of to add the values stored in two variables.
the variable on left from the value Like the way we add values in
on the right. mathematics, we can store values in
Example: : x /= y different variables and perform an
additional operation. The addition of
It can also be written as x = x / y
these variables is displayed as an output
Increment operator of the program.

Increment operator adds one to the For example, performing add operation
value. on a variable "a" holding value "3" and a
variable "b" holding value "4" will result
Example: A=8 in an output "7".
B=A++ To understand this arithmetic operation
The output of B will be 9 (A+1) better, let us understand how to
implement it practically in
A++ has the same meaning as A=A+1 programming. For this, we are going to
take example of platform -
Decrement operator
https://arcade.makecode.com/. Let us
Decrement operator subtracts one from refer to the steps below understand
the value. more in details.

25 | P a g e
Variables using block coding

26 | P a g e
Variables using block coding

27 | P a g e
Variables using block coding

28 | P a g e
Variables using block coding

29 | P a g e
Variables using block coding

30 | P a g e
Variables using block coding

31 | P a g e
Variables using block coding
Subtraction Division
Subtraction arithmetic operation is used Division arithmetic operation is used to
to subtract the values stored in one divide the value stored in one variable by
variable from another variable. Like the the value stored in another variable. Like
way we subtract values in mathematics, the way we divide values in
we can store values in different variables mathematics, we can store values in
and perform subtraction operations. different variables and perform division
Subtraction of these variables is operations. Division of these variables is
displayed as an output of the program. displayed as an output of the program.

For example, performing subtraction For example, performing division


operation on a variable "a" holding value operation on a variable "a" holding value
"10" and a variable "b" holding value "8" "2" and a variable "b" holding value "2"
will result in an output "2". will result in an output "1".
Multiplication Modulus (Remainder)
Multiplication arithmetic operation is Modulus operator (%) calculates the
used to multiply the values stored in two remainder when two integer variables
variables. Like the way we multiply are divided. Please note that this
values in mathematics, we can store operation can only be performed on
values in different variables and perform integer variables.
multiplication operations. Multiplication
of these variables is displayed as an For example, performing modulus
operation on a variable "a" holding value
output of the program.
"9" and variable "b" holding value "3" will
For example, performing multiply result in an output "0" as there is no
operation on a variable "a" holding value remainder in this operation
"2" and a variable "b" holding value "2"
will result in an output "4"

3.9 Quiz time


Objective Type Questions

Question 1 An integer data type can hold decimal values.


Option 1 True
Option 2 False
Answer: Option 2
Question 2 Variables must be defined with a name and a data type before they
can be used
Option 1 True
Option 2 False
Answer: Option 1

32 | P a g e
Variables using block coding

Question 3 Which of the following is not a valid variable name in python?

Option 1 _test
Option 2 11test
Option 3 Test13
Option 4 Test_2
Answer: Option 2

Question 4 Fill in the blanks to declare sum equal to a + b (int __ = a __b)

Option 1 Sum,+
Option 2 Var,-
Option 3 Bool,+
Option 4 Add,+
Answer: Option 1

Question 5 Which of the following data type is used to store decimal values?

Option 1 Integer
Option 2 Float
Option 3 Boolean
Option 4 String
Answer: Option 2

Question 6 How many times should a data type be mentioned for a variable

Option 1 Everywhere the variable is used


Option 2 When entering variable’s value
Option 3 When printing a variable’s value
Option 4 Only once; When declaring the variable
Answer: Option 4

Question 7 Which of the following symbol is used to multiply variables?

Option 1 *
Option 2 +
Option 3 x
Option 4 %
Answer: Option 1

33 | P a g e
Variables using block coding
Question 8 What is the alternative of y=y+9

Option 1 y=x+9
Option 2 y+=9
Option 3 y-=9
Option 4 x=+9
Answer: Option 2

Question 9 Y++ has the same meaning as

Option 1 Y=Y+1
Option 2 X=+2
Option 3 y-=6
Option 4 X=x-5
Answer: Option 1

Question 10 Which of the following symbol is used to find the remainder?

Option 1 *
Option 2 +
Option 3 x
Option 4 %
Answer: Option

Short Answer Questions


1. Define variables in programming
2. Can we declare two variables in a program with the same name?
3. What are the common Data Types in programming?
4. Name a data type that can store exponential values
5. Write the pseudocode to perform an addition operation on two variables in a
program

Higher Order Thinking Skills (HOTS)


1. Create a flowchart to perform different mathematical operations (Multiplication,
Subtraction, Addition, Division) on two or more variables.
Teacher’s Note: The teacher should explain to the student’s different mathematical
operations that can be done and encourage them to write the pseudocode and then
create the flowchart for various operations starting from two variables and then
three variables.

34 | P a g e
Variables using block codingControl with conditionalsVariables
using block codingVariables using block coding
2. Create a project in https://arcade.makecode.com/ to perform Modulus operation
on two variables in a program.
Teacher’s Note: The teacher should explain modulus operation to the students and
encourage them to write the pseudocode and then create the block code project for
two variables.

Applied Project
Using block coding, create your normal school day (Monday to Friday).
Here are some guidelines:

Getting ready for school

• Look at your timetable and pack your school bag


• If PE is there packing your PE uniform and shoes
At school

• Attend the morning session with subjects Math, English and science
• A decision on what to play during recess
• Attend the afternoon session subjects
• Lunch Break
• PE Class
After reaching home

• Have snacks
• Depending on the day choose the class you must attend.
Monday-Karate, Tuesday-Math Class, Wednesday-Swimming and Thursday-
Chess, Friday-Dance (You can use variables to define the class you have to
attend)

3.10 What did you learn in this chapter?

• What are variables and how they are used in programming


• Ways of naming variables.
• Different data types in programming and its usage
• Various operations that we can perform of different data types in programming

35 | P a g e
Control with conditionals

CONTROL WITH CONDITIONALS


4.1 Lesson Structure
1. Logical Operations
a. AND
b. OR
c. NOT
d. Combining Logical Operators
e. Relational Operators
f. Exercise
g. Practice Challenges
2. Nested Conditional Statements
a. Exercises
b. Practice Challenges

4.2 Lesson Plan


Sub-Topics Number of Method
Periods

Logical Operations 3 Theory


• AND
• OR
• NOT
• Combining Logical Operators

Relational Operators

Logical Operations - Exercise Practical

Logical Operations – Practice Challenges Practical

Nested Conditional Statements Theory

Nested Conditional Statements - Exercise Practical

Nested Conditional Statements – Practice 2 Practical


Challenges

36 | P a g e
Control with conditionals
4.2.1 Teacher’s Notes
Discuss: What are logical operators in real life?
The teacher should introduce logical operations to the students by using real -life
examples like those mentioned in the curriculum. They can also ask the students to
come up with such examples to encourage critical thinking.

Discuss: Different types of logical operators?


The teacher should introduce AND, OR and NOT operators with examples. They should
ensure that the children are not confused with these terms and explain the pseudo code
to the students to improve their conceptual understanding.
Discuss: How to combine different operators?

Combining operators should be explained with the flowcharts provide d. The teacher can
also ask students to draw a few flowcharts on their own to test their understanding.
Students might be familiar with relational operators already, so using them in examples
and pseudo code should be helpful.
Activity: Place students in groups of three or four and guide them through the
exercises
For the exercise section, the teacher should make sure that the children are comfortable
with the Make Code platform and they have it working on their computers. The practice
challenges can be solved in several ways and do not have a definite answer.
Assignment: Allow students to perform at least one practice exercise on their
own
The teacher should encourage students to come up with unique solutions to the
challenges in order to test their creativity and understanding of the subject.

37 | P a g e
Control with conditionals
In the earlier chapters, we discussed
how to handle decisions in a flow chart.
4.3 What will you learn in
Now we shall see how to implement it in
this chapter? our code.
• What are conditions and how to We can do things conditionally in our
apply them in real life? programs using if statements or if/else
• What are the different types of
statements combined with logical
operators?
• How to combine multiple operators. Logical operators work like
operators? Boolean variables and return either
• Apply logical operations in block TRUE or FALSE.
coding
The three most important logical
operators are AND, OR and NOT.

4.4 Arranging blocks

Logical
In the image below, we see several blocks operators
arranged in a specific order. Every time
we place a new block, we apply logic to
build a diagonal line with blocks marked
with arrows. This logic in coding terms AND OR NOT
are called conditions.

4.5 And operator

AND operator is used to determine if two


or more conditions are true. If all the
conditions are true, the AND operator
returns TRUE. If any one of the
conditions fail, the AND operator returns
FALSE. In some programming languages
AND operator is denoted by “&&”
symbol.
Similarly, every day we take many For example - you should go to bed only
decisions depending on our situation. after you have completed your
For instance, when it is cold outside, we homework and the time is past 8 PM.
wear warm clothes, otherwise, we don't.
Here, if we want to derive the logical
operation from this scenario, we have
the following conditions:

Condition 1: Have you completed


Logical operators are fundamental
homework?
blocks that can be used to build a
decision-making capability in your code. Condition 2: Is the time past 8 PM?

38 | P a g e
Control with conditionals
And the decision we are deriving is: Like the previous example, if we want to
derive the logical operation from this
Decision: Should you go to bed?
scenario, we have the following
Based on this we can write the below conditions:
pseudo code:
Condition 1: Is it sunny outside?
IF (Homework completed) AND (Time is past Condition 2: Is it raining outside?
8 PM)
THEN And the decision we are deriving is:
Go to bed
ELSE Decision: Should we carry an umbrella?
Do not go to bed
END The pseudocode for this will look like
below:

Let us now try to see the different IF (It is sunny outside) OR (It is raining
combinations possible with the above outside)
pseudo code. THEN
Carry an umbrella
Condition 1 Condition 2 Decision ELSE
Have you Is the time Should Do not carry an umbrella
completed past 8 PM? you go to END
homework? bed?
Yes Yes Yes Shown below are the different possible
No Yes No combinations for the above example.
Yes No No
No No No Condition 1 Condition 2 Decision
Is sunny? Is raining? Carry
umbrella?
Having this example in mind, let us now Yes Yes Yes
see how this is different from OR Yes No Yes
operator. No Yes Yes
No No No
4.6 OR Operator
Let us now look at the NOT operator.

The OR operator is used to determine if


either one of two or more conditions is 4.7 NOT Operator
TRUE. If any of the condition is true, the
OR operator returns TRUE. If all the
We use the NOT operator to reverse or
conditions fail, the OR operator simply
negate a condition. If the condition is
returns FALSE. In some programming
true, NOT will return false and vice-
languages OR operator is denoted by
versa. In some programming languages
“||” symbol. NOT operator is denoted by “!” symbol.
For example - We should carry an
For example, you can go to play only if it
umbrella when either it is sunny, or it is
is not raining, otherwise, you must stay
raining. Otherwise, we should not carry
indoors.
it.

39 | P a g e
Control with conditionals
Unlike the previous examples, here we
have only one condition.

Condition: Is it raining?
Decision: Go out to play?

The pseudocode for this will look like


below:

IF NOT (It is raining)


THEN
Go out to play
ELSE
Stay indoors
END

And the corresponding table for this is


below.

Is it raining? Go out to play?


Yes No
No Yes

4.8 Combining logical


operators

Sometimes, we need to combine different


logical operators to create a complex
expression. Imagine your library is open
on Monday between 10 AM to 12 PM OR
on Wednesday between 3 PM to 5 PM.
Let's see how this looks on a flowchart.
Let us write a pseudocode for this.

IF (Day == Monday AND (Time >= 10 AM


AND Time <=12 PM)) OR
(Day == Wednesday AND (Time >= 3
PM AND Time <= 5 PM))
THEN
Library Open
ELSE
Library Closed
END

The corresponding flowchart for the


pseudocode will be like following.

40 | P a g e
Control with conditionals

4.9 Quiz time

Let us now answer some questions based on the above example.

Question 1

Situation Today is Tuesday, and the time is 4 PM. Is the library open now?
Option 1 Yes
Option 2 No
Answer: Option 2
Question 2

Situation Today is Monday and the time being 10.30 AM. Is the library open
now?
Option 1 Yes
Option 2 No
Answer: Option 1
Question 3

Situation Today is Friday, and the time is 12 PM. Is the library open now?
Option 1 Yes
Option 2 No
Answer: Option 2

Question 4

Situation Today is Wednesday, and the time is 10.30 AM. Is the library open
now?
Option 1 Yes
Option 2 No
Answer: Option 2
Question 5
Situation Today is Wednesday and the time is 3.30 PM. Is the library open
now?
Option 1 Yes
Option 2 No
Answer: Option 1

41 | P a g e
Control with conditionals
If age>19 then adult
• Print “child or teenager or adult”
4.10 Relational operators
depending on the condition
satisfied
In our previous example, we got
introduced to some relational operators
like greater than equals (>=), equals (==),
and less than equals (<=).
Let us now look at the full list of
relational operators.

Operator Symbol Example Meaning


Greater > x>y x greater
than than y
Equal to == x == y x is equal
to y
Less than < x<y x is less
than y
Greater >= x >= y x is either
than or greater
equal to than or
equal to y
Less than <= x <= y x is either
or equal less than
to or equal
to y
Not equal != x! = y x is not
to equal to y

4.11 Activity: Are you a


teen?

In this activity we will check if you are a


child, teenager or an adult. 4.12 Activity: Dynamic
Steps to create the flowchart: backgrounds
Let us now do an activity to test our
• Input your age understanding of conditions and
• If age<13 then child, else, operators.
If age>=13 and <=19 then
teenager, else, You should try this exercise on the
MakeCode platform.

42 | P a g e
Control with conditionals
To access the MakeCode editor, open your favorite browser and go to
https://arcade.makecode.com/. Create a new project as shown below.

Now follow the below steps to see how we can use conditionals in block coding.

43 | P a g e
Control with conditionals

Follow the following steps to complete the exercise.

44 | P a g e
Control with conditionals

45 | P a g e
Control with conditionals

46 | P a g e
Control with conditionals

When you change the height to 10 the loop will go inside the if condition as the height
is greater than 5 AND less than 20. The background color will change to green.

So, what did we learn from this That is correct! The background color
activity? change to green as height is greater than
5 AND less than 20.
You have now learnt how to create
conditional statements. What do you
think will the output of the code be if you
change the height to 15?

47 | P a g e
Control with conditionals
4.13 Nested Conditional 4.14 Activity: The
Statements remainder problem

Under certain circumstances, we might Let us now run through a practice


have to deal with complex scenarios exercise to understand the problem
where using a single if-else loop might stated above. You should try this
not be enough. exercise on the MakeCode platform.
Suppose we want to check if a number First, create a new project for this
is divisible by 2 or 3 or both 2 and 3. exercise using the steps shown at the
beginning of exercise 3.1.6 and name
In this case, we first need an IF condition
the project 'Nested Conditional
to check if the number is divisible by 2.
Statements'
Within that condition, we can implement
another IF condition to check if the Follow the below steps to complete the
number is divisible by 3 or not. By doing exercise.
so, we can check the divisibility of the
number.

48 | P a g e
Control with conditionals

49 | P a g e
Control with conditionals

50 | P a g e
Control with conditionals

Result The background should change to red


for numbers that are divisible both by 2
You can now change the value of the and 3. It should change to orange for
number to 6 and check if the
numbers that are divisible by 2 but not
background of the controller changes. by 3.

51 | P a g e
Control with conditionals

4.15 Quiz time


Objective Type Questions

Using the below pseudocode answer the following questions(Question 1 to 4) :

IF (Day == Saturday OR Day == Sunday


IF (Time >= 12 AM AND Time <=8 PM))
THEN
Holiday
ELSE
School Day
ELSE
School day
END

Question 1 Today is Monday and time is 11.30 AM. Is today a school day?

Option 1 True
Option 2 False
Answer: Option 1

Question 2 Today is Saturday and time is 1.30 AM. Is today a Holiday?


Option 1 True
Option 2 False
Answer: Option 1

Question 3 Today is Wednesday and time is 5.30 AM. Is today a school day?

Option 1 True
Option 2 False
Answer: Option 1

Question 4 Today is Sunday and the time is 09.30 PM. Is today a Holiday?

Option 1 True
Option 2 False
Answer: Option 2

Question 5 Logical operators can be used to make decisions in our code


Option 1 True
Option 2 False
Answer: Option 1

52 | P a g e
Control with conditionals
Question 6 Which operator is used if the statement evaluates true only if both
the expressions are true
Option 1 And
Option 2 Or
Option 3 Not
Option 4 None of the above
Answer: Option 1

Question 7 Which operator is used if the statement evaluates true only if only
one of the expressions is true
Option 1 And
Option 2 Or
Option 3 Not
Option 4 None of the above
Answer: Option 2

Question 8 Which of the following operator is used to reverse or negate a


condition
Option 1 And
Option 2 Or
Option 3 Not
Option 4 None of the above
Answer: Option 3
Based on the flowchart for Are you a teen, let us now try to answer the below questions.

Question 9 Your father’s age is 35. In which category will he fall?

Option 1 Child
Option 2 Teenager
Option 3 Adult
Option 4 None of the above
Answer: Option 3

Question 10 Your sister’s age is 19. In which category will she fall?

Option 1 Child
Option 2 Teenager
Option 3 Adult
Option 4 None of the above
Answer: Option 2

53 | P a g e
Control with conditionals
Short Answer Questions
1. What are the different types of logical operators? Explain with examples.
2. Explain with example on how to combine different logical operators.
3. Write the pseudocode using logical operators to decide if today is a school day or
not.
(Monday-Friday: School day;
Sunday: Holiday;
1st and 3rd Saturday: Holiday;
2nd and 4th Saturday: School day)

Higher Order Thinking Skills (HOTS)


1. Create an if-else block with Different logical operators (And, Or, Not) and set different
background colors or images on the controller.
Teacher’s Note: The teacher should explain the students' questions first to understand
it and write the corresponding block code/Pseudocode for the questions. The teacher
should encourage the students to do the problem on their own. The block code
background color/Image will be different for all the students

2. Create a nested if-else block to check if a number is divisible by 3 or 5 or both.


3. Create a nested if-else block using NOT to check if a number is a power of 2 or 3 or
both.
Teacher’s Note: The teacher should explain the student’s questions first so that the
students can understand it and write the corresponding block code/Pseudocode for the
questions. The teacher should encourage the students to do the problem by their own. For
the nested if block the students can form groups to solve the problem and come up with a
solution together.

Applied Project

Create a program using conditional statements for a sports event. If an event occurs,
THEN what happens?
Here are some guidelines:

• If a referee blows the whistle


• If the time limit is reached
• If a player crosses the finish line first
• If a player touches a friend during tag
• If a ball goes outside the boundary

54 | P a g e
Control with conditionals
Teacher’s Note: The teacher should explain the student’s questions first so that the
students can understand it and write the corresponding block code/Pseudocode for the
questions. The teacher should encourage the students to do the problem by their own.
For the nested if block the students can form groups to solve the problem and come up
with a solution together.

4.16 What did you learn in this chapter?

• You should now have an understanding on the AND, OR, NOT logical operators.
• You can now combine different logical operators.
• You have understood how to apply logical operators in block coding.
• Understand nested conditional statement in block coding.

55 | P a g e
Loops using block coding

LOOPS USING BLOCK CODING


The teacher should introduce loops to
5.1 Lesson Structure the students by using real-life examples
to make it more understandable to
1. Introduction to Loops students. They can also ask the
2. Increment Loops students to come up with such examples
3. Activity: Building a Music Player to encourage critical thinking.
4. Entry Criteria
5. Exit Criteria Activity: Place students in groups of
6. Break and Continue Loops three or four and guide them through
7. Nested Loops the exercises
8. Assignment For the exercise section, the teacher
should make sure that the children are
comfortable with the Make Code
5.2 Lesson Plan
platform and they have it working on
Number their computers. The practice challenges
Sub-Topics of Method can be solved in several ways and do
Periods not have a definite answer.
Introduction to Assignment: Allow students to
Theory
Loops perform at least one practice
Increment Loops Theory exercise on their own
Different types of
Theory The teacher should encourage students
Loops
to come up with unique solutions to the
Activity: Building a
Practical challenges in order to test their creativity
Music Player
6 and understanding of the subject.
Entry Criteria Theory
Exit Criteria Theory
Break and Continue
Practical
Loops

Nested Loops Practical

Assignment 1 Practical

5.2.1 Teacher’s Notes


Discuss: What are loops in real life?

56 | P a g e
Loops using block coding
5.3 What will you learn in
this chapter? This was easy. Now consider a
requirement where you we need to print
numbers in incremental order from 1 to
• What are loops? 1000. Although it is possible to print it
• How to increment loops? following the above pseudocode, it will
• Different types of loops get a very tedious and lengthy process.
• Concept of nested loops This is where loops come into the picture
to make this task easier. You can use the
concept of loops and get the desired
output by writing just a few lines of code.
5.4 Introduction to loops

5.5 Increment Loops


There are many tasks in our day to day
life which we repeat at specific intervals,
like eating meals, taking a bath, going to Loops provide the facility to execute a
school etc. There is a very similar block of code repetitively, based on a
concept to this in programming where condition. This block of code is executed
we need to repeat certain lines of code at repeatedly till the time a specified
specific interval or till specified condition condition remains true. This condition is
is met. checked based on loop's control
variable. Whenever this condition
In programming, repetition of a line or a
results in false, the loop terminates. It is
block of code is also known as iteration. very important to keep this thing in
A loop is an algorithm which executes a
block of code multiple times till the time
a specified condition is met. Therefore, Start
we can say that a loop iterates a block of …This program demonstrates printing
code multiple times till the time alphabets a to c
mentioned condition is satisfied. Print a
For example, consider that you want to Print b
print alphabets a to c on the screen. We
Print c
can do so by printing the values a, b and
c by writing 3 lines of code. Let us now End
look at the following pseudocode:
Output:
A
B
C

57 | P a g e
Loops using block coding
mind while programming that the
condition should result false at a certain
point in time. Otherwise, this block of
code will enter an infinite loop.

Execution of loops is based on


iterations. To run a block of code in a
loop, one needs to set a condition and
set its number of iterations. Each time
the condition is true, and the block of
code executes once, it is counted to be
one iteration. Before moving to the next
iteration, one needs to increase the
count of iteration to two. This is called
as incrementing a loop.

For example, if you need to print


numbers 0 to 4, you will execute a block
of code with Print statement in five
iterations. With each passing iteration,
you will increment the count by one.
Below are the two important benefits of
loops:

1. Reduces lines of code


2. Code becomes easier to
understand
Let us understand loops with a
flowchart. The following flowchart prints
5.6 Different types of loops
the numbers 1 to 5. Here every time the
condition (Count < 5) is true, "Print
count" gets executed. So, we do not have Loops make our code more manageable
to write the "Print" statement multiple and organized. Let us now see what the
times. The loop takes care of that. What different types of loops are:
is important to note is every loop must
have an exit condition. In our example 1. While Loop
the exit condition is (Count < 5). The loop 2. For Loop
will exit when the condition becomes 3. Nested Loop
false. Also, most loops will have a
variable which in programming terms is
called counter variable. The counter
variable keeps track of how many times
the loop executed. In this example, the
“count” variable is our counter.
Often, counter variables are
incremented within the loop.

58 | P a g e
Loops using block coding

The While Loop This is the result for the code

The While loop can execute a set of I will eat healthy food every day.
commands till the condition is true I will eat healthy food every day.
While Loops are also called conditional I will eat healthy food every day.
loops.
Once the condition is met then the loop
is finished. Let’s now see a few examples: Example 3 - Print a statement 3 times
after that print different statement.
Example 1 – Print number from 1 to 15
Condition: Till the time the test
Here, if we want to derive the loop from expression remains true we will run the
this scenario, we have the following body of while loop printing statement 1
conditions: and after the condition is false, we will
print statement 2.
Condition: Write from 1 to 15
And the decision we are deriving is:
And the decision we are deriving is:
Decision: Have we printed the
Decision: Have we reached 15 statement 1 three times, if yes then print
Based on this we can write the below the statement 2
pseudocode: Based on this we can write the below
pseudocode:
y=0
while y < 15
y=0
y+=1 while y < 3
print(y) y+=1
print(“Please,”)
else
Example 2 - Print a statement 3 times print(“I want to play.”)
using while loop.
Condition: Till the time the test This is the result for the code
expression remains true we will run the
body of while loop Please,
Please,
And the decision we are deriving is:
Please,
Decision: Have we printed the I want to play.
statement 3 times
Based on this we can write the below Example 4 - Print number from 10 to 1
pseudocode: Condition: Till the time the test
expression remains true we will run the
y=0 body of while loop printing statement
while y < 3 and after the condition is false the loop
y+=1 will stop
print(“I will eat healthy food every day.”)
And the decision we are deriving is:

59 | P a g e
Loops using block coding
Decision: Have we printed 1 I will study every day.
Based on this we can write the below I will study every day.
I will study every day.
pseudocode:
I will study every day.
I will study every day.
x = 10
while x==1
print(x) Example 2 – Use for loop to print all the
x-=1 odd numbers from a list.
The pseudo code for this will look like
This is the result for the code below:

10 list1 = [13, 24, 7, 49, 74, 29]


9 for x in list1:
8 if x % 2!= 0:
7 print(x, end = " ")
6
5
4 This is the result for the code
3
2 13 7 49 29
1

Example 3 – Use for loop to print all the


The For Loop even numbers from a list.

For loop is needed for iterating over a The pseudo code for this will look like
sequence. A for loop executes for a below:
specific number of times.
list2 = [13, 24, 7, 49, 74, 29]
Now let us see a few examples: for x in list2:
if x % 2 == 0:
Example 1 – We need to print a print(x, end = " ")
statement five times using the for loop
The pseudo code for this will look like
below: This is the result for the code

for i in range(5) 24 74
print(“I will study every day.”)
i++

range(5) used in the above snippet The Nested Loop


returns a sequence of numbers from 0 to
5. This is the result for the code Any loop in program may contain
another loop inside it. When there is a
loop inside another loop, it is called a
nested loop. How it works is that first
success condition of outer loop triggers
the inner loop which runs and reaches

60 | P a g e
Loops using block coding
completion. This combination of loops
inside loop is helpful while working with
requirements where user wants to work
of multiple conditions simultaneously.
There is no restriction on how many
loops can be nested inside a loop.

To understand the concept of Nested


loops better, consider an example of an
Analogue clock. An analogue clock has
one hand as the nested loop and every
full rotation knocks the minute hand on
by one etc. We can take this even further Now that we know the concept of loops
to say that clocks are just a form of the let us try this out with block coding. We
counting system. This is how nested will build a very simple music player
loops work in real life. using the concepts of loops.
Below is an example of nested loop
5.7 Activity: Building a music
player

We will implement the concept of


incrementing loops with the help of
Arcade platform. Let us go through the
below exercise step by step.

61 | P a g e
Loops using block coding

62 | P a g e
Loops using block coding

When you click on the play for the above The flow starts with 1 and in each
exercise that we created, you will hear iteration, it increments once. Each time
the music 10 times. The loop repeats loop completes once iteration, and you
itself 10 times (counter that we had set). will hear music once.

63 | P a g e
Loops using block coding
5.8 Entry Criteria while defining a loop. As without an exit
criterion, the program tends to enter in
an infinite loop. These criteria differ from
Now that we have understood about program to program as per the
different loops and its iterations, it is requirement.
also important to understand when and
where should one start iterating through For example, while creating a loop to
these loops. When the looping condition print numbers from 1 to 1000, exit
is true then the code will enter a loop. it criteria is that loop should exit the block
is important to define an entry criterion of code when the 1000th number is
for the loop to ensure that the loop runs. printed, else the program will enter an
infinite loop.
Entry criteria is defined as a condition
that must be met before starting a
specific task. It is a set of conditions that
must exist before you can start a task. 5.10 Break Statement
These criteria differ from program to
program as per the requirement.
The break statement modifies the
For example, To start a car you need normal flow of execution while it
petrol/diesel. If your fuel tank is empty terminates the existing loop and
your car won’t start. So, the entry continues execution of the statement
criteria for the car to start is fuel tank following that loop. Break statement is
should not be empty. required as sometimes you want to
break out of a loop early when a
5.9 Exit Criteria condition is met.

Let us now understand Break Statement


Now that we have understood about with help of below pseudocode:
loops and its iterations, it is also
important to understand when and
where should one stop iterating through
these loops. As mentioned in the
previous topic, it is crucial to keep in
mind that the looping condition should
result false at a certain point of time
while programming. Otherwise, the
block of code will enter an infinite loop.
To ensure that the loop does not enter
an infinite loop, it is important to define
an exit criterion for the loop.

Exit criteria is defined as a condition


that must be met before completing a
specific task. It is a set of conditions that
must exist before you can declare a
program to be complete. Exit criteria is
one of the most important components

64 | P a g e
Loops using block coding
As we see the control skips the lines force the next iteration and skip some
after the break statement and executes lines of code within the loop.
the first statement outside the loop.
Let us now understand continue
Example – Use break statement to statements with the below pseudocode:
print number from 9 to 5 and another
print statement when you encounter
break

The pseudo code for this will look like


below:

a=9
while a > 0:
print 'Current variable is :', a
a = a -1
if a == 5:
break

print "Bye!"

This is the result for the code As you can see, as soon as the continue
statement is encountered, the lines
Current variable is :9 below the continue statement are
Current variable is :8 skipped. But unlike the break
Current variable is :7 statement, the loop is not terminated.
Current variable is :6 Instead, the control jumps to the
Bye! beginning of the loop.

Example – Use continue statement to


print number from 9 to 0 and does not
print when the value is 5
5.11 Continue Statement The pseudo code for this will look like
below:

Whenever a program comes across a


continue statement, the control skips b=9
while b > 0:
the execution of remaining statements
b = b -1
inside the loop for the current iteration
if b == 5:
and jumps to the beginning of the loop
for the next iteration. If the loop's continue
condition is still true, it enters the loop print 'Current variable is :', a print
"Bye!"
again, else the control will be moved to
the statement immediately after the
loop. This is somewhat similar to break
statement and is used when we want to This is the result for the code

65 | P a g e
Loops using block coding
Current variable is :9
Current variable is :8
Current variable is :7
Current variable is :6
Current variable is :4
Current variable is :3
Current variable is :2
Current variable is :1
Current variable is :0
Bye!

Now that we know the concepts of loops


let us do an activity.

5.12 Activity: A tale of


two villages

In this exercise, we will use basic coding


concepts to bring two villages together in
Minecraft: Education Edition. You
setup Minecraft education edition from
https://education.minecraft.net/get-
started

66 | P a g e
Loops using block coding

67 | P a g e
Loops using block coding

68 | P a g e
Loops using block coding

There are many other challenges that can be done. Let us do one more to help villagers
learn how to farm.

69 | P a g e
Loops using block coding

Refer https://education.minecraft.net/hour-of-code-2020 for the entire activity.

70 | P a g e
Loops using block coding

5.13 Quiz time


Objective Type Questions

Question 1 The if the statement is used to execute some code if a statement is


true.
Option 1 True
Option 2 False
Answer: Option 1

Question 2 An else statement should always be after an if statement which


executes when the code is false.
Option 1 True
Option 2 False
Answer: Option 1

Question 3 A while loop statement repeatedly executes a statement as long as


the condition remains true
Option 1 True
Option 2 False
Answer: Option 1

Question 4 Without a statement that eventually evaluates the while loop


condition to false, the loop will continue indefinitely
Option 1 True
Option 2 False
Answer: Option 1

Question 5 A for loop executes for a specific number of times


Option 1 True
Option 2 False
Answer: Option 1

Question 6 A continue statement is used to skip all the remaining statements in


the loop and moves the control back to the top of the loop.
Option 1 True
Option 2 False
Answer: Option 1

Question 7 When a break statement is encountered inside a loop, the loop is


immediately terminated, and the program execution moves on to the
next statement in the loop.
Option 1 True
Option 2 False
Answer: Option 1

71 | P a g e
Loops using block coding
Question 8 Doing something over and over again or repeating code is called as
Option 1 Code
Option 2 loop
Option 3 Program
Option 4 Bug
Answer: Option 2

Question 9 Which is the correct operator for equality testing?


Option 1 ==
Option 2 =
Option 3 !=
Option 4 +=
Answer: Option 1

Question 10 What is the output of the below pseudocode?


Option 1 5
Option 2 10
Option 3 15
Option 4 0

count = 0;

sum = 0;

while (count < 5)


{

sum = sum + count;

count = count + 1;

}
print sum;

Answer: Option 1

Question 11 Which letter won’t print while running the below pseudocode?
Option 1 ‘d’
Option 2 ‘c’
Option 3 ‘n’
Option 4 ‘o’

72 | P a g e
Loops using block coding

for letter in "coding":

if letter == "i":
break
print(letter)

print("End")

Answer: Option 3

Question 12 Which letter won’t print while running the below pseudocode?

Option 1 ‘g’
Option 2 ‘o’
Option 3 ‘d’
Option 4 ‘i’

for letter in "coding":

if letter == "i":
continue

print(letter)
print("End")

Answer: Option 4

Short Answer Questions


1. Define loops and nested loops in programming
2. What is an exit criterion?
3. How do we increment loops?
4. What is break and continue statements? Give few examples.
5. Create a flowchart to print all prime numbers

73 | P a g e
Loops using block coding
Higher Order Thinking Skills (HOTS)
Now that you know the concept of Nested Loops. Using Arcade MakeCode platform
create an example for nested loops.
Teacher’s Note: The teacher should explain to the students regarding nested loops. The
teacher should encourage the students to do the problem independently and come with
different examples. For the nested block, the students can form groups to solve the
problem and come up with a solution together.

Applied Project
Write a program using loops that ask the user to enter an even number. If the number
entered does not display an appropriate message and asks them to enter a number
again. Do not stop until an even number is entered. Print a congratulatory message at
end.
Teacher’s Note: The teacher should encourage the students to form groups or to do the
problem by their own.

5.14 What did you learn in this chapter?

• You should now have an idea of what are loops and how they are used in
programming?
• Incrementing loops
• Different types of loops
• What is entry and exit criteria in loops and its usage?
• Break and continue statements
• Concept of nested loops

74 | P a g e
References

REFERENCES

Microsoft. 2021. Microsoft MakeCode Arcade. [Online]. [25 February 2021].


Available from: https://arcade.makecode.com

Microsoft. 2021. Microsoft MakeCode for Minecraft. [Online]. [25 February 2021].
Available from: https://minecraft.makecode.com

Microsoft. 2021. Computer Science Subject Kit | Minecraft: Education Edition.


[Online]. [25 February 2021]. Available from:
https://education.minecraft.net/class-resources/computer-science-subject-kit

Microsoft. 2020. Activity: We Built a Zoo. [Online]. [25 February 2021]. Available
from: https://education.minecraft.net/class-resources/computer-science-subject-
kit

ACM, Inc. 2021. Code of Ethics. [Online]. [25 February 2021]. Available from:
https://www.acm.org/code-of-ethics

Microsoft. 2020. Hour Of Code 2020 | Minecraft: Education Edition. [Online]. [25
February 2021]. Available from: https://education.minecraft.net/hour-of-code-
2020

75 | P a g e

You might also like