What is Pseudocode?
Pseudocode is a way of writing steps for a computer program using simple words instead of a
programming language. It helps us plan what we want a computer to do before we actually write
the real code.
Why Do We Use Pseudocode?
● It is easy to read and understand.
● It helps us organize our thoughts before coding.
● It is like writing a recipe for a computer to follow.
Basic Rules for Writing Pseudocode
1. Use simple language – Write in plain English.
2. Use clear steps – Write each instruction on a new line.
3. Use keywords – Some common words in pseudocode:
o START – To begin the program
o INPUT – To take information from the user
o OUTPUT – To display information on the screen
o PROCESS – To perform calculations or actions
o IF...THEN – To make decisions
o WHILE or FOR – To repeat actions
o END – To show that the program has finished
Example 1: A Simple Pseudocode for Adding Two Numbers
pgsql
CopyEdit
START
PRINT "Enter first number"
INPUT number1
PRINT "Enter second number"
INPUT number2
sum number1 + number2
PRINT "The sum is", sum
END
Explanation:
● The program asks the user to enter two numbers.
● It calculates the sum.
● It displays the result.
Example 2: A Pseudocode for Checking If a Number is Even
or Odd
pgsql
CopyEdit
START
PRINT "Enter a number"
INPUT number
IF number MOD 2 = 0 THEN
PRINT "The number is even"
ELSE
PRINT "The number is odd"
ENDIF
END
Explanation:
● The program takes a number from the user.
● It checks if the number can be divided by 2 without a remainder.
● If yes, it prints "The number is even."
● Otherwise, it prints "The number is odd."
Loops in Pseudocode
Loops help us repeat a task multiple times.
Example 3: Counting from 1 to 5 Using a Loop
pgsql
CopyEdit
START
FOR count FROM 1 TO 5 DO
PRINT count
ENDFOR
END
Explanation:
● The program prints numbers from 1 to 5 using a loop.
Activity for Students
Try to write pseudocode for:
1. Asking for a name and saying hello (e.g., "Hello, Alice!").
2. Checking if a number is greater than 10 or not.
3. Printing numbers from 1 to 10 using a loop.
Final Tips
● Always write clear and simple steps.
● Use capital letters for keywords (START, INPUT, OUTPUT, etc.).
● Think like a computer—give one instruction at a time.
1. What is Pseudocode?
Pseudocode is a way of writing steps for a computer program using simple words instead of
actual code. It helps us plan what we want a computer to do before we write real code.
1. Variables
What is a Variable?
A variable is like a box that stores information. We can change its value anytime.
Example: Storing and Displaying a Name
pgsql
CopyEdit
START
name "Alice"
PRINT "Hello", name
END
Explanation:
● We create a variable called name and store "Alice" in it.
● We display "Hello Alice".
Activity:
Try writing pseudocode to store your age and print it.
2. Data Types
What are Data Types?
Data types tell the computer what kind of information we are storing.
Data
Example Description
Type
String "Hello" Text or words
Integer 5, 100, -20 Whole numbers
Float 3.14, 10.5 Decimal numbers
TRUE, Yes or No, On or
Boolean
FALSE Off
Example: Storing Different Data Types
pgsql
CopyEdit
START
name "John" // String
age 10 // Integer
height 4.5 // Float
isStudent TRUE // Boolean
PRINT name, age, height, isStudent
END
Activity: Try storing your favorite color in a variable and printing it.
3. IF Conditions
What is an IF Condition?
An IF condition checks if something is true or false and runs a different action based on the
answer.
Example: Checking If a Number is Positive or Negative
pgsql
CopyEdit
START
PRINT "Enter a number"
INPUT number
IF number > 0 THEN
PRINT "The number is positive"
ELSE
PRINT "The number is negative"
ENDIF
END
Activity: Write pseudocode to check if a number is greater than 100.
4. Loops
What is a Loop?
A loop repeats an action multiple times. There are two types:
1. FOR Loop (When we know how many times to repeat)
2. WHILE Loop (Repeats until a condition is false)
Example: Using a FOR Loop to Count from 1 to 5
pgsql
CopyEdit
START
FOR count FROM 1 TO 5 DO
PRINT count
ENDFOR
END
Activity: Write a FOR loop to print numbers from 1 to 10.
Example: Using a WHILE Loop to Count Until 5
pgsql
CopyEdit
START
count 1
WHILE count <= 5 DO
PRINT count
count count + 1
ENDWHILE
END
Activity: Write a WHILE loop that prints numbers from 10 to 1.
5. Arrays
What is an Array?
An array is like a list that stores multiple values in one variable.
Example: Storing and Printing Fruit Names
START
fruits ["Apple", "Banana", "Cherry"]
PRINT fruits[0] // Prints Apple
PRINT fruits[1] // Prints Banana
PRINT fruits[2] // Prints Cherry
END
Activity: Create an array of three favorite colors and print them.
Example: Using a Loop to Print All Items in an Array
css
CopyEdit
START
fruits ["Apple", "Banana", "Cherry"]
FOR i FROM 0 TO 2 DO
PRINT fruits[i]
ENDFOR
END
Activity: Write a loop to print all numbers in an array [5, 10, 15, 20].
Final Tips
● Use simple steps – One instruction at a time.
● Use capital letters for keywords – (START, INPUT, OUTPUT, IF, FOR, etc.)
● Think like a computer – Give clear instructions.
1. Variables
What is a Variable?
A variable is like a box that stores information. We can change its value anytime.
Example: Storing and Displaying a Name
pgsql
CopyEdit
START
name "Alice"
PRINT "Hello", name
END
Activity: Write pseudocode to store your favorite food and print it.
2. Data Types
What are Data Types?
Data types tell the computer what kind of information we are storing.
Data Example Description
Type
String "Hello" Text or words
Integer 5, 100, -20 Whole numbers
Float 3.14, 10.5 Decimal numbers
Boolean TRUE, FALSE Yes or No, On or Off
Example: Storing Different Data Types
START
name "John" // String
age 10 // Integer
height 4.5 // Float
isStudent TRUE // Boolean
PRINT name, age, height, isStudent
END
3. IF Conditions
What is an IF Condition?
An IF condition checks if something is true or false and runs a different action based on the
answer.
Example: Checking If a Number is Positive or Negative
START
PRINT "Enter a number"
INPUT number
IF number > 0 THEN
PRINT "The number is positive"
ELSE
PRINT "The number is negative"
ENDIF
END
Multiple IF Conditions
We can check more than one condition using ELSE IF.
Example: Checking Grade Based on Marks
START
PRINT "Enter marks"
INPUT marks
IF marks >= 90 THEN
PRINT "Grade: A"
ELSE IF marks >= 75 THEN
PRINT "Grade: B"
ELSE IF marks >= 50 THEN
PRINT "Grade: C"
ELSE
PRINT "Grade: F"
ENDIF
END
Activity: Write pseudocode to check if a person is a child (0-12), teenager (13-19), or adult
(20+).
4. Loops
What is a Loop?
A loop repeats an action multiple times.
FOR Loop (Repeats a set number of times)
START
FOR count FROM 1 TO 5 DO
PRINT count
ENDFOR
END
WHILE Loop (Repeats until a condition becomes false)
START
count 1
WHILE count <= 5 DO
PRINT count
count count + 1
ENDWHILE
END
REPEAT UNTIL Loop (Repeats until a condition is true)
START
count 1
REPEAT
PRINT count
count count + 1
UNTIL count > 5
END
Difference Between WHILE and REPEAT UNTIL:
● WHILE checks the condition before running.
● REPEAT UNTIL runs at least once before checking the condition.
Activity: Write a REPEAT UNTIL loop that asks the user for a password until they enter
"1234".
5. Arrays (Lists of Data)
1D (One-Dimensional) Arrays
A 1D array stores multiple values in a single row.
Example: Storing and Printing Fruit Names
START
fruits ["Apple", "Banana", "Cherry"]
PRINT fruits[0] // Prints Apple
PRINT fruits[1] // Prints Banana
PRINT fruits[2] // Prints Cherry
END
Using a Loop to Print All Items in a 1D Array
START
fruits ["Apple", "Banana", "Cherry"]
FOR i FROM 0 TO 2 DO
PRINT fruits[i]
ENDFOR
END
Activity: Write a loop to print all numbers in an array [5, 10, 15, 20].
2D (Two-Dimensional) Arrays
A 2D array is like a table with rows and columns.
0 1 2
0 Apple Banana Cherry
1 Orange Grape Mango
Example: Storing and Printing a 2D Array
START
fruits [["Apple", "Banana", "Cherry"],
["Orange", "Grape", "Mango"]]
PRINT fruits[0][0] // Prints Apple
PRINT fruits[1][2] // Prints Mango
END
Using a Loop to Print All Items in a 2D Array
START
fruits [["Apple", "Banana", "Cherry"],
["Orange", "Grape", "Mango"]]
FOR row FROM 0 TO 1 DO
FOR col FROM 0 TO 2 DO
PRINT fruits[row][col]
ENDFOR
ENDFOR
END
Activity: Write pseudocode to store and print student marks in a 2D array.