No history yet

Introduction to Programming

What is Programming?

At its heart, programming is simply telling a computer what to do. Think of it like writing a recipe for a very literal-minded chef. You need to provide a list of precise, step-by-step instructions. If you tell the chef to "add a bit of salt," they'll be stumped. How much is a bit? You need to say, "add 1 teaspoon of salt."

Computers are the same. They can perform amazing tasks at incredible speeds, but they don't have intuition or common sense. Programming is the art of breaking down a large task into small, logical steps that a computer can understand and execute.

Programming is the process of creating a set of instructions that tell a computer how to perform a task.

Talking to Computers

We can't write our instructions in English or Spanish. Computers have their own language, which at the lowest level is just a series of ones and zeros called binary. Trying to write complex programs in binary would be nearly impossible for a human.

This is where programming languages come in. They act as a bridge, allowing us to write instructions in a way that's more readable for us. A special program called a compiler or interpreter then translates our code into the binary instructions the computer's processor can execute.

Lesson image

There are hundreds of programming languages, from Python and Java to C++ and Ada. While their syntax, the rules for how you write them, differs, they all share the same fundamental concepts.

The Building Blocks of Code

Every program, from a simple calculator to a complex video game, is built using a few core components.

Variable

noun

A storage location with a specific name, which holds a known or unknown quantity of information referred to as a value.

Think of a variable as a labeled box where you can store information. You can put data into the box, see what's inside, or change its contents. For example, in a game, you might have a variable called player_score to keep track of a player's points.

The box also needs to know what kind of information it holds. This is called a data type. You can't do math with a word, and you can't find the length of a number. Data types tell the computer how to interpret and work with the data in a variable.

Data TypeDescriptionExample
IntegerWhole numbers42, -100
FloatNumbers with a decimal point3.14, -0.001
StringText"Hello, world!"
BooleanTrue or false valuetrue, false

Beyond storing data, programs need to make decisions and repeat actions. This is handled by control structures. They direct the "flow" of the program.

  • Conditionals: These are if-then-else statements. They check if a condition is true and execute different code based on the outcome. If the player's score is greater than 100, then display a "You win!" message, else continue the game.

  • Loops: These repeat a block of code multiple times. For example, a loop could draw every single frame of an animation, one after another, until the animation is complete.

Algorithms and Logic

An algorithm is the specific recipe you create to solve a problem. It's the plan before you start coding. How do you find the average of a list of numbers? First, you create a variable to hold the sum, initialized to zero. Then, you loop through each number, adding it to the sum. Finally, you divide the sum by how many numbers were in the list. That's an algorithm.

Programming is fundamentally about logic. It's about taking a problem, breaking it down into a logical sequence of steps (the algorithm), and then translating that logic into a programming language using variables, data types, and control structures.

With these core ideas, you have the foundation needed to start exploring any programming language.

Quiz Questions 1/6

What is the fundamental purpose of programming?

Quiz Questions 2/6

In programming, what is the best analogy for a variable?