Pseudocod
e
Introduction to Pseudocode
What is Pseudocode?
Pseudocode is a structured representation of an
algorithm written in plain English combined with
programming-style constructs.
Key Characteristics
• Not a real programming language
• No strict syntax rules like Python or Java
• Uses standard logical structures
• Easy to read and understand
Why Use Pseudocode?
• Ensures fairness across programming languages
• Focuses on problem-solving skills
• Eliminates syntax-related confusion
Importance of Pseudocode
•Helps break down complex problems
•Improves logical thinking
•Acts as a bridge between ideas and code
Presentation Rules
Font and Style
Monospaced font (fixed width)
Uniform font size
Indentation
Shows block structure
Essential for readability
Logical nesting must be clear
Example:
IF Age >= 18
THEN
OUTPUT "Eligible"
ENDIF
Keywords, Identifiers
Keywords
Written in UPPERCASE
Examples:
IF, ELSE, ENDIF
FOR, WHILE, REPEAT
INPUT, OUTPUT
Identifiers
Mixed case
Must describe purpose
Examples:
TotalMarks
StudentCount
Comments in Pseudocode
Purpose of Comments
Explain what the code does
Improve readability
Useful for learners
Rules
Begin with //
Each comment occupies its own line
Example:
// Calculate average marks
Total ← Maths + Science
Average ← Total / 2
Data Types
What is a Data Type?
A data type defines:
• The kind of value stored
• The operations allowed on the value
Atomic Data Types
Type Meaning
INTEGER Whole numbers
REAL Decimal numbers
CHAR Single character
STRING Text
BOOLEAN TRUE or FALSE
Literals
What is a Literal?
A literal is a fixed value written directly in the code.
Examples:
Age ← 15
Grade ← 'A'
Name ← "Riya"
Passed ← TRUE
Rules to Remember
CHAR → single quotes
STRING → double quotes
REAL → must contain decimal point
Identifiers – Naming Rules
Rules
Must begin with a letter
Can include digits
No spaces or symbols
Case-insensitive
Good Practice
Use meaningful names
Avoid single letters unless standard
Good: TotalMarks
Bad: tm1
Assignment Statements
Assignment Operator
Uses arrow ←
Assigns value from right to left
General Format:
Variable ← Expression
Examples:
Score ← 0
Score ← Score + 5
Area ← Length * Breadth
Arrays
What is an Array?
An array is a collection of multiple values of the same
data type, stored under one name.
Why Arrays Are Used
Store large sets of data
Reduce number of variables
Improve program structure
Declaring Arrays
Declaration Format:
DECLARE <identifier> : ARRAY[lower:upper] OF
<datatype>
Example:
DECLARE Marks : ARRAY[1:50] OF INTEGER
DECLARE Names : ARRAY[1:30] OF STRING
Index usually starts from 1
Using Arrays
Accessing Elements:
Marks[1] ← 85
Names[3] ← "Amit"
Using Arrays in Loops:
FOR i ← 1 TO 50
Marks[i] ← 0
NEXT i
Arrays cannot be assigned in bulk without loops.
INPUT and OUTPUT Operations
INPUT
Used to accept user data.
INPUT Name
INPUT Age
OUTPUT
Used to display results.
OUTPUT "Welcome ", Name
OUTPUT "Age: ", Age
Multiple outputs can be combined in one statement.
Arithmetic Operations
Operators
Addition (+)
Subtraction (−)
Multiplication (*)
Division (/)
Special Operators
DIV → integer quotient
MOD → remainder
Example:
Quotient ← 17 DIV 5
Remainder ← 17 MOD 5
Logical Operators
Operators
AND
OR
NOT
Example:
IF Age >= 18 AND Citizen = “Indian”
THEN
OUTPUT "Eligible"
ENDIF
Logical expressions always return BOOLEAN values.
Selection – IF Statement
Single Condition:
IF Temperature > 37
THEN
OUTPUT "Fever"
ENDIF
Dual Condition:
IF Marks >= 40
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
Used when decision depends on conditions.
CASE Statement
When to Use
When one variable has multiple fixed values
Example:
CASE OF Day
1 : OUTPUT "Monday"
2 : OUTPUT "Tuesday"
3 : OUTPUT "Wednesday"
OTHERWISE OUTPUT "Invalid"
ENDCASE
Cleaner and clearer than multiple IF statements.
Iteration – FOR Loop
When to use
Known number of repetitions
Example:
FOR i ← 1 TO 10
OUTPUT i
NEXT i
With STEP:
FOR i ← 10 TO 1 STEP -1
OUTPUT i
NEXT i
WHILE Loop – Pre-Condition
Characteristics
Condition tested first
Loop may not run at all
Example:
WHILE Count > 0 DO
OUTPUT Count
Count ← Count - 1
ENDWHILE
REPEAT UNTIL Loop – Post-Condition
Characteristics
Executes at least once
Condition tested at end
Example:
REPEAT
INPUT Password
UNTIL Password = "Admin"
Example of Pseudocode
BEGIN
NUMBER num
OUTPUT "Enter a number:"
INPUT num
IF num > 0 THEN
OUTPUT "Entered number is positive"
ELSE IF num < 0 THEN
OUTPUT "Entered number is negative"
ELSE
OUTPUT "Entered number is zero"
ENDIF
END