Programming is the process of creating instructions for computers to follow. These instructions, written in programming languages, tell computers what to do step by step. Think of it like writing a recipe - you provide detailed steps for the computer to execute.
A program is a set of instructions that tells a computer how to perform a specific task. Programming languages are the tools we use to write these instructions.
Programming is everywhere in modern life - from the apps on your phone to the websites you visit, from video games to scientific research. Learning to program gives you the power to create, automate, and solve problems.
Variables are containers that store data. Think of them as labeled boxes where you can put information and retrieve it later. Every variable has a name and holds a value.
// JavaScript example
let name = "Neo";
let age = 30;
let isAwake = true;
// Python example
name = "Neo"
age = 30
is_awake = True
Common data types include:
Control structures allow you to control the flow of your program. They let you make decisions and repeat actions.
// JavaScript
if (age >= 18) {
console.log("You are an adult");
} else {
console.log("You are a minor");
}
// For loop - repeat a specific number of times
for (let i = 0; i < 5; i++) {
console.log("Count: " + i);
}
// While loop - repeat while condition is true
let count = 0;
while (count < 5) {
console.log("Count: " + count);
count++;
}
Functions are reusable blocks of code that perform specific tasks. They help organize your code and avoid repetition.
// JavaScript function
function greet(name) {
return "Hello, " + name + "!";
}
// Using the function
let message = greet("Neo");
console.log(message); // Output: Hello, Neo!
// Python function
def greet(name):
return f"Hello, {name}!"
message = greet("Neo")
print(message) # Output: Hello, Neo!
Try this exercise to practice what you've learned:
Create a function that converts temperature from Celsius to Fahrenheit.
Formula: °F = (°C × 9/5) + 32
Example:
Input: 25°C
Output: 77°F
Try writing this function yourself, then test it with different values. If you get stuck, ask the AI Assistant for help!
Congratulations on completing the Introduction to Programming! You've learned the fundamental concepts that form the foundation of all programming languages.
Ready to continue? Here are your next steps: