Computer Intro to Programming
Programming is the process of writing instructions that tell a computer what to do. These instructions, written in a programming language, form a program (also called software or code). Every application you use — from a calculator to a social media platform — started as lines of code written by a programmer.
You do not need to be a mathematician or a genius to program. Programming is a learnable skill that follows logical patterns. This topic gives you a solid foundation to understand how programming works before you write a single line of code.
What is a Program?
A program is a sequence of precise, unambiguous instructions that a computer follows to complete a task. Computers do exactly what the program tells them — nothing more, nothing less. If the instructions are wrong, the result is wrong.
Think of a program as a recipe. A recipe gives step-by-step instructions to produce a dish. A program gives step-by-step instructions to produce a result. Both must be precise and in the correct order.
Recipe (for a human): Program (for a computer): 1. Heat oil in pan 1. Get input: two numbers 2. Add onions, stir 3 min 2. Add the two numbers together 3. Add tomatoes, stir 5 min 3. Display the result 4. Add spices 4. End 5. Serve hot
Programming Languages
A programming language is a formal language with defined syntax (grammar rules) and semantics (meaning rules) used to write programs. There are hundreds of programming languages, each designed with different strengths.
Language │ Main Use Cases ────────────┼────────────────────────────────────────────── Python │ Data science, AI, web, automation, beginners JavaScript │ Web development (front-end and back-end) Java │ Android apps, enterprise applications C / C++ │ Operating systems, game engines, embedded systems C# │ Windows apps, games (Unity engine) Swift │ iOS and macOS applications Kotlin │ Android apps SQL │ Database queries HTML/CSS │ Web page structure and styling (not general-purpose) R │ Statistical computing, data analysis Go │ Cloud services, system programming Rust │ Systems programming with safety guarantees
How Code Becomes Instructions the CPU Can Run
CPUs understand only machine code — binary instructions specific to that CPU's architecture. Programming languages use human-readable words and symbols. Something must translate between them.
Compiler
A compiler reads the entire source code, translates it all at once into machine code, and produces an executable file. You run the executable directly. C, C++, Java (to bytecode), and Rust use compilers.
Source Code (.c file)
│
▼
Compiler (reads all at once)
│
▼
Machine Code / Executable (.exe)
│
▼
CPU runs it directly
Interpreter
An interpreter reads source code line by line and executes each line immediately. No separate executable is produced. Python, Ruby, and JavaScript (in browsers) use interpreters.
Source Code (.py file)
│
▼
Interpreter (reads line 1 → executes, reads line 2 → executes...)
│
▼
Results produced as each line runs
Core Programming Concepts
Variables
A variable is a named container that stores a value. The value can change as the program runs.
name = "Rahul" # stores the text "Rahul" in the variable 'name' age = 25 # stores the number 25 in 'age' score = 0 # starts at 0, may increase later
Data Types
Every piece of data in a program has a type that defines what kind of value it is and what operations apply to it.
Type │ Example │ Can Do ──────────┼─────────────────────┼────────────────────────── Integer │ 42, -7, 1000 │ Math: add, subtract, etc. Float │ 3.14, -0.5, 9.99 │ Math with decimals String │ "Hello", "Rahul" │ Join, search, split text Boolean │ True, False │ Logic: AND, OR, NOT List/Array│ [1, 2, 3, "apple"] │ Store multiple values
Operators
Operators perform operations on values.
Arithmetic: + - * / % ** (+ add, - subtract, * multiply, / divide, % remainder, ** power) Comparison: == != > < >= <= (checks if values are equal, not equal, greater, etc.) Logical: and or not (combine conditions) Assignment: = += -= *= (store values in variables)
Conditionals (If-Else)
Conditionals let a program make decisions — running different code depending on whether a condition is true or false.
temperature = 38
if temperature > 37:
print("You have a fever.")
else:
print("Temperature is normal.")
Output: You have a fever.
Decision Flow:
temperature = 38
│
▼
Is temperature > 37?
│ │
YES NO
│ │
"Fever" "Normal"
Loops
Loops repeat a block of code multiple times. They eliminate the need to write the same instructions over and over.
For Loop (repeat a set number of times):
for i in range(1, 6):
print(i)
Output:
1
2
3
4
5
While Loop (repeat while a condition is true):
count = 0
while count < 3:
print("Hello")
count = count + 1
Output:
Hello
Hello
Hello
Functions
A function is a named, reusable block of code that performs a specific task. Functions take input (parameters), perform an action, and optionally return output.
def add_numbers(a, b): ← Define the function
result = a + b
return result ← Send back the answer
total = add_numbers(10, 25) ← Call the function
print(total) ← Output: 35
Functions keep code organised, readable, and reusable. Instead of writing the same 10-line calculation 50 times, write it once as a function and call it 50 times.
Algorithms
An algorithm is a step-by-step procedure for solving a problem. Every program implements one or more algorithms. Sorting a list, finding the shortest path between two points, or searching a database all involve well-defined algorithms.
Algorithm: Find the largest number in a list Step 1: Set "largest" = first number in the list Step 2: Look at each remaining number Step 3: If the current number > largest, set largest = current number Step 4: After all numbers checked, return "largest" Input: [4, 9, 2, 15, 7] Output: 15
Programming Paradigms
Different programming styles (paradigms) exist for solving problems in different ways:
- Procedural: Code runs as a sequence of instructions, step by step. C is procedural.
- Object-Oriented (OOP): Code is organised around objects that have data (attributes) and behaviour (methods). Java and Python support OOP.
- Functional: Code is built from pure functions with no side effects. Haskell and parts of Python and JavaScript support functional style.
Debugging: Finding and Fixing Errors
A bug is an error in code that causes incorrect behaviour. Every programmer encounters bugs regularly — even expert programmers with decades of experience.
Types of Errors:
Syntax Error → Code violates language rules (misspelled keyword, missing bracket)
Caught before the program runs.
Runtime Error → Code runs but crashes due to an impossible operation
(dividing by zero, accessing memory that does not exist)
Logic Error → Code runs without crashing but produces wrong results
(wrong formula, incorrect condition)
Debugging involves systematically identifying which part of the code produces the wrong result, understanding why, and fixing it. Debugging skills are as important as writing code itself.
