Introduction to Programming Logic

Think Like A Developer

Computers can follow instructions quickly and proficiently, but someone has to write instructions for them to follow in the first place. That's where developers come in!

That set of instructions—written by a developer—is what we call a computer program. When developers write programs, they must consider the following two questions:

  • What do I want the computer to do?

  • How do I tell the computer to do that?

What Do I Want the Computer to Do?

First, developers should think about the steps that a computer must take to complete a task. For example, to add two numbers together, a computer might need to complete the following steps:

  • Ask the user to enter a number.

  • Ask the user to enter a second number.

  • Add the numbers together.

  • Display the result.

Review the list of steps and ask yourself the following questions:

  • Have I included all of the steps?

  • Have I included steps that I don't need?

  • Do any steps need to be broken down into smaller steps?

  • Are the steps in the right order?

When you are confident that you've listed all of the steps, you're ready to proceed.

How Do I Tell The Computer To Do That?

As a developer, you'll learn to translate your list of instructions into a language that the computer understands. There are many programming languages, and each language includes its own rules or syntax.

For example, in the Java programming language, the steps for adding two numbers together would resemble the following example:

System.out.println("Please enter a number.");
int num1 = Integer.parseInt(scan.nextLine());

System.out.println("Please enter another number.");
int num2 = Integer.parseInt(scan.nextLine());

int sum = num1 + num2;
System.out.println("The sum of your numbers is " + sum);

We'll be learning a lot of syntax throughout this course. Translating steps into a programming language might seem difficult at first, but it will become second nature in no time!


Think Like A Computer

Computers don't understand the world in the same way that we do. For instance, think about the steps you might take to make a peanut butter and jelly sandwich:

  1. Get two slices of bread, peanut butter, and jelly.

  2. Get utensils and a plate.

  3. Spread peanut butter and jelly on each slice of bread.

  4. Put the two slices of bread together.

These steps might make sense to humans, but a computer might need more information.

For Step 3, for example, a computer might need to know the following:

  • How many times do you spread?

  • In what direction do you spread?

  • What amount do you spread?

  • What utensil do you use to spread?

  • Which slice of bread do you spread first?

You'll soon discover that learning to program requires you to think in greater detail about the steps that the computer must take to accomplish something. Sometimes the steps will seem obvious, but you will need to explain them in more detail for the computer to succeed.