We have learned that a computer works by following instructions. But who writes these instructions? The answer is a programmer. A programmer writes instructions in a special language that the computer can understand. This process of writing instructions for a computer is called programming.
In this chapter, we will learn what a program is and what programming means. We will study programming languages and how they are different from human languages. We will learn about algorithms and flowcharts, which help us plan our programs. We will also learn basic programming concepts like variables, data types, and control structures. By the end of this chapter, you will be able to write a simple program and draw a flowchart to solve a problem.
A program is a set of instructions given to a computer to perform a specific task. For example, a program can be written to add two numbers, to draw a picture, or to play a game. A computer follows the instructions of a program step by step, exactly in the order they are written.
The process of writing a program is called programming. The person who writes programs is called a programmer.
A program is like a recipe. A recipe tells a cook, step by step, how to make a dish. If we miss a step or change the order, the dish may be wrong. Similarly, a computer follows the steps of a program exactly, and a mistake anywhere will give a wrong result.
Programs are written to solve problems. Before writing a program, we must first understand the problem clearly and plan how to solve it.
Human beings communicate in languages like English and Hindi. A computer understands only machine language, which is made of 0s and 1s. It is impossible for humans to write long programs in 0s and 1s. So, special programming languages were created that are closer to human language.
Programming languages are of two main types:
Low-level languages: These are close to machine language. Machine language and assembly language are low-level languages. They are hard for humans to read and write.
High-level languages: These use English-like words and are easy for humans to understand and write. Examples are Python, Java, C, C++, and Scratch. High-level programs must be translated into machine language with the help of a compiler or interpreter before the computer can run them.
Python is a very popular high-level language and is often the first language students learn. It is easy to read because its commands look like simple English sentences.
An algorithm is a step-by-step plan to solve a problem. Before writing a program, we first write an algorithm. An algorithm uses simple steps in plain language, without any computer code.
Let us see an algorithm to add two numbers:
Step 1: Start. Step 2: Take two numbers, A and B. Step 3: Add A and B and store the result in S. Step 4: Show the result S. Step 5: Stop.
An algorithm must have the following qualities:
Algorithms help us think clearly about a problem. A good algorithm always leads to a good program.
A flowchart is a diagram that shows the steps of an algorithm using different shapes and arrows. It helps us see the logic of a program visually, which makes it easier to understand and check.
The main symbols of a flowchart are:
Oval (start/stop): The oval shape shows the beginning (Start) and the end (Stop) of the flowchart.
Rectangle (process): A rectangle shows a processing step, like adding two numbers or moving data.
Parallelogram (input/output): A parallelogram shows where we take input or show output.
Diamond (decision): A diamond shows a decision where the program must choose yes or no.
Arrows: Arrows connect the shapes and show the direction of flow.
For example, a flowchart to check if a number is even has an oval to start, a parallelogram to take the number, a diamond to decide whether the number divided by 2 gives remainder 0, and then output "Even" or "Odd" before the stop oval.
In a program, we need a place to store data. A variable is a named storage location in a program where data can be kept and changed. Just as we label a box to keep our toys, we give names to variables to keep data.
A variable has a name, like "age" or "marks", and it stores a value. The value of a variable can change during the program. For example, in the algorithm above, A, B, and S are variables.
Data stored in a program can be of different types, called data types. The common data types are:
Integer: Whole numbers without a decimal point, like 5, -3, or 100.
Float: Numbers with a decimal point, like 3.14 or 9.5.
String: A sequence of characters like a word or sentence, for example "Hello" or "Class 6".
Boolean: A value that is either true or false.
A program usually runs its statements one after another from top to bottom. But sometimes we want the program to make decisions or repeat work. For this, we use control structures. The main control structures are:
Sequence: The statements run one after another in order. This is the normal flow of a program.
Decision (if-else): The program checks a condition and does different work depending on whether the condition is true or false. For example, if marks are more than 33, print "Pass", else print "Fail".
Loops (repetition): A loop makes the program repeat a set of instructions several times. For example, we can use a loop to print "Happy Birthday" ten times instead of writing the print command ten times.
Loops save us a lot of typing and make programs shorter. The computer repeats the instructions inside the loop until a condition is met.
Scratch is a visual programming language made for children. In Scratch, we do not type code in words. Instead, we drag and join colourful blocks, like puzzle pieces, to build a program. Each block is an instruction, and joining the blocks creates a script.
In Scratch:
Scratch teaches us the logic of programming in a fun way. When we make a cat move on the stage, we are actually writing a program using blocks.
Learning programming helps us in many ways. It makes us think logically and solve problems step by step. It improves our creativity, because we can create games, animations, and projects. Programming is also used everywhere: in smartphones, games, websites, robots, and even in machines at school and hospital. A person who can program can create new things and find solutions to problems. Programming is not only for future jobs; it helps us think better every day.
| Flowchart Symbol | Shape | Meaning |
|---|---|---|
| Start / Stop | Oval | Beginning or end of the flowchart |
| Process | Rectangle | A processing step |
| Input / Output | Parallelogram | Taking input or showing output |
| Decision | Diamond | A yes or no decision |
| Data Type | Example |
|---|---|
| Integer | 5, -3, 100 |
| Float | 3.14, 9.5 |
| String | "Hello", "Class 6" |
| Boolean | true, false |
In this chapter, we were introduced to the wonderful world of programming. We learned that a program is a set of instructions that tells a computer what to do, and a programmer is the person who writes these instructions. We studied programming languages and understood the difference between low-level and high-level languages. We learned how to plan our solution with an algorithm and present it visually with a flowchart. We explored the important concepts of variables, data types, and control structures like decisions and loops. We also had fun learning about Scratch, where we build programs with colourful blocks. Programming teaches us to think logically and solve problems creatively. As we continue to learn, we will be able to create games, animations, and useful programs of our own.