No history yet

Programming Fundamentals

Giving Computers Instructions

Programming is the art of telling a computer what to do. Think of it like writing a recipe for a very literal-minded chef. The chef, our computer, will follow your instructions exactly as you write them. If you say “add a pinch of salt,” it needs to know precisely what a “pinch” is. If you forget a step, the final dish might not turn out right.

To communicate these precise instructions, we use programming languages. Just as humans use languages like English or Spanish, programmers use languages like Python, Java, or C++. While they look different, they all share the same fundamental concepts. Learning these concepts is like learning the grammar of programming; once you understand them, picking up any specific language becomes much easier.

Storing Information

A program needs to remember things to be useful. It might need to keep track of a user's name, the score in a game, or the price of an item. To do this, we use variables.

Variable

noun

A storage location in a computer's memory that holds a value. It has a name, which is used to refer to that value.

You can think of a variable as a labeled box where you can store one piece of information. You give the box a name (like score or username) and put a value inside it. You can look at the value later or replace it with a new one.

But computers are picky about what kind of information you store. You can't just throw anything into a box; you have to tell the computer the type of data it will hold. This is known as the variable's data type.

Data TypeDescriptionExample
IntegerWhole numbers42, -100
StringText, a sequence of characters"Hello!"
BooleanA true or false valuetrue, false

Making Decisions and Repeating Actions

Programs rarely run in a straight line from start to finish. They need to react to different situations and perform repetitive tasks. This is where control structures come in. They control the flow of the program's execution.

One of the most common control structures is the conditional statement. It allows a program to make a decision. It works on a simple if-then logic: if something is true, then do this. You can also add an else part: if not, then do something else.

For example: If it is raining outside, then I will take an umbrella. Else, I will wear sunglasses.

Another essential control structure is the loop. Loops are for repetition. Instead of writing the same instruction ten times, you can tell the computer to repeat it ten times. This is incredibly useful for tasks like processing a list of items or drawing a shape on the screen.

WHILE there are still cookies on the plate:
    Take one cookie
    Eat the cookie

Packaging Instructions

As programs grow, you'll find yourself needing to perform the same sequence of actions over and over again. Instead of rewriting the same code, you can package it into a function.

Function

noun

A named, reusable block of code that performs a specific task. It can be "called" or invoked from other parts of the program.

Think of a function like the "brew" button on a coffee machine. You don't need to know how it grinds the beans, heats the water, and filters the coffee. You just press the button, and it performs the whole task for you. Functions work the same way. You define a set of instructions, give it a name (like make_coffee), and then you can "call" that function anytime you need that task done.

This makes code much cleaner, more organized, and easier to manage. If you need to change how the task is done, you only have to update the code in one place: inside the function.

// Defining the function
FUNCTION greet_user(name):
    PRINT "Hello, " + name

// Calling the function
greet_user("Alice")
greet_user("Bob")

These concepts—variables, data types, control structures, and functions—are the bedrock of all programming. Master them, and you'll be ready to build anything you can imagine.

Quiz Questions 1/6

What is the primary role of a programming language?

Quiz Questions 2/6

A named location in memory used to store a piece of information that can be changed is called a(n) _______.