Use Sophia to knock out your gen-ed requirements quickly and affordably. Learn more
×

Programming and Debugging Basics

Author: Sophia

what's covered
In this lesson, you will explore the foundational logic and problem-solving strategies that power computer programming. You will not need to install coding tools; instead, you’ll work with code snippets, logic flow, and debugging examples to learn how programmers think and work.

Specifically, this lesson will cover the following:

Table of Contents

1. Introduction to Programming

Programming is the process of writing instructions a computer can understand and execute. These instructions are written using programming languages such as Python, JavaScript, R, or C++, and they tell the computer how to perform tasks, such as calculating numbers, powering a mobile app, or running a database.

EXAMPLE

A website form might ask for your email address. Behind the scenes, a short program checks it to make sure that the address is in the correct format (like [email protected]). If it isn’t, the program tells the browser to show an error.

There are many different programming languages designed for different types of tasks. Some are great for building websites, whereas others are used to make mobile apps and games or even to help scientists analyze data. The good news? You don’t need to learn them all! But it’s helpful to get a sense of what they’re used to do and what makes each one unique. Here’s a quick comparison of a few popular languages:

Programming Languages and Their Uses
Language Where It’s Used What Makes It Special
Python Automating tasks, data science, simple games, websites Easy to read and great for beginners; used in many fields
JavaScript Making websites interactive (e.g., buttons and animations) Runs in the browser and helps websites “do things”
C++ Building video games, operating systems, and devices Fast and powerful, but harder to learn
Java Android apps, business software Works on many types of computers; used by large companies
SQL Storing and searching data in databases Focuses on asking questions about data, not general programming
Swift iPhone and iPad apps (Apple devices) Made by Apple; modern
R Data science, statistics, academic research Built for analyzing and visualizing data; great for statistics

term to know
Programming
Writing instructions for a computer to execute.


2. Pseudocode

No matter which language a programmer uses, they all follow the same basic logic. Programming logic is like giving clear, step-by-step instructions to a small child. It helps the computer know what to do, when to do it, and how to repeat actions. In order to learn this, you don’t need to understand any programming language. Instead, you’ll use something called pseudocode, which is a way to plan and explain what a program should do using plain language instead of real code.

Let’s look at four core logic structures that show up in almost every program.

Variables are like containers that hold information. You create a variable by giving it a name and assigning it a value, such as a number or a word. Then, the program can remember and use it when needed.

EXAMPLE


Make a variable score called and set to 90 

Conditionals allow a program to make choices. The computer checks a condition, for example, whether a number is above or below a certain value, and then decides what to do next based on the answer.

EXAMPLE


If score is greater than or equal to 60 
  Print "Pass" 
Else 
  Print "Fail"

Iteration, also called looping, repeats actions until a certain condition is met. In everyday terms, it’s like “keep printing until the printer runs out of paper.” Loops can also be created to repeat a certain number of times, such as “move forward four steps.”

EXAMPLE


Set counter to 1
While counter is less than or equal to 3 
  Print "Check complete" 
  Increase counter by 1

This pseudocode creates a loop that runs three times. It starts by setting a counter to 1, then prints “Check complete” as long as the counter is less than or equal to 3. Each time the message prints, the counter increases by 1. After the third time, the loop ends.

A practical example might be a task reminder system that checks whether three daily goals, such as replying to emails, completing a training module, and submitting a report, are done. Instead of writing separate checks for each task, the program uses a loop to repeat the same action for each one. This kind of logic saves time and helps keep routines organized, especially when managing work, school, and personal responsibilities.

Computers are powerful but not smart in the way people are. They don’t understand vague instructions. Instead, they need precise, step-by-step directions to complete even the simplest task. This is what programming logic is all about.

Let’s take a familiar example: making toast. If you tell a person, “Make me toast,” they’ll use experience and context to figure it out. But if you gave that instruction to a computer, it wouldn’t know where to begin.

To make toast with programming logic, you’d have to break the task into individual, unambiguous instructions, like this:

step by step
Making Toast in Programming Logic
  1. Go to the kitchen
  2. Open the bread bag
  3. Take out one slice of bread
  4. Place the slice into the toaster slot
  5. Press the toaster lever down
  6. Wait 2 minutes
  7. Remove the toast
  8. Place it on a plate

big idea
Programmers think like this all the time: break a big task into small, exact steps the computer can follow. This is called algorithmic thinking.

try it
Imagine you’re a student checking your grades. You’ve taken five tests, and you want to know:
  • What’s my average score? Am I passing?
Whether you’re tracking your GPA, evaluating a team’s performance, or analyzing data in a spreadsheet, calculating an average is one of the most common things you’ll do with a computer. Before you write a single line of pseudocode, it helps to stop and think like a programmer. Solving a problem with code isn’t just about knowing a language. It’s about planning logic first. Here are the key questions programmers ask themselves before they start coding:
  1. What is the problem or goal I need to solve?
  2. What input values will the program work with?
  3. What output or result should the program produce?
  4. What variables will I need to store and track values?
  5. Does the order of steps matter for getting the correct result?
Let’s use those five questions to plan our pseudocode.
  1. What’s the problem?
    Calculate the average score from a list of test scores.
  2. What’s the input?
    A list of numbers (the test scores).
  3. What’s the output?
    A single number: the average.
  4. What variables do I need?
    total (to store the sum)
    count (to count the scores),
    average (to hold the result)
  5. What’s the correct order of steps?
    1. Add each score to the total
    2. Count how many scores,
    3. Divide the total by the count
    4. Print the result
Now that you have considered these questions, you can write the steps in pseudocode.

step by step
Step 1: Set total to 0
  • We create a “container” called “total” to store the sum of all scores.
  • We start with 0 because we haven’t added any scores yet.
  • Think of this like getting an empty basket to collect apples.
Step 2: Set count to 0
  • We create another “container” called “count” to keep track of how many scores we’ve seen.
  • We start with 0 because we haven’t counted any scores yet.
  • This is like having a counter that starts at zero.
Step 3: For each score in test_scores
  • This means “look at every single test score, one at a time.”
  • Imagine you have a stack of test papers, and you’re going through them one by one.
  • test_scores is our list of numbers (e.g., 85, 92, 78, 96, 88).
Step 4: Add score to total
  • Take the current score and add it to our running total.
  • If the first score is 85, then the total becomes 0 + 85 = 85.
  • If the next score is 92, then the total becomes 85 + 92 = 177.
  • And so on ...
Step 5: Increase count by 1
  • Every time we look at a score, we add 1 to our counter.
  • After the first score, count = 1.
  • After the second score, count = 2.
  • This tells us how many scores we’ve processed.
Step 6: Set average to total divided by count
  • Once we’ve gone through all scores, we do the math.
  • If total = 439 and count = 5, then average = 439 ÷ 5 = 87.8.
Step 7: Print average
  • Display the result so that we can see it.
  • This would show something like “The average is 87.8.”
After completing these steps, you should generate pseudocode like this:


Set total to 0   
Set count to 0
For each score in test_scores   
  Add score to total   
  Increase count by 1
Set average to total divided by count   
Print average

terms to know
Programming Logic
The use of clear, step-by-step instructions to tell a computer exactly what to do and when.
Pseudocode
A way to plan and explain what a program should do using plain language instead of real code.
Variable
A container that holds information, such as a number or a word, which a program can remember and use later.
Conditional
A logic structure that allows a program to make decisions based on whether a statement is true or false.
Iteration (Looping)
A process of repeating actions until a condition is met or for a set number of times.

3. Debugging

Debugging is the process of finding and fixing problems (called bugs) in a program. These problems can prevent the program from working properly or cause it to behave in unexpected ways.

did you know
In the early days of computing, the term “bug” was already used by engineers to describe technical glitches. However, it gained widespread recognition in 1947 because of an incident involving Rear Admiral Grace Hopper, a pioneering computer scientist and one of the first women to make significant contributions to the field.

While working on the Harvard Mark II electromechanical computer, Hopper and her team encountered a malfunction. Upon investigation, they discovered that a moth had become trapped in one of the computer’s relays, causing the issue. They carefully removed the moth and taped it into the computer’s logbook, noting it as the “first actual case of bug being found.” This humorous yet significant event popularized the terms “bug” and “debugging” in the context of computer science.

There are three common types of bugs programmers encounter:

  1. Syntax Errors
    1. The rules of the language were broken (e.g., missing punctuation or incorrect spelling).
    2. These prevent the program from running at all.
  2. Runtime Errors
    1. The program crashes while running, often because of unexpected input or dividing by zero.
    2. Example: The program asks the user for a number, but they type in a word.
  3. Logic Errors
    1. The program runs, but it does the wrong thing.
    2. These are the hardest to catch because the code is technically “valid” but does not behave as intended.
Debugging isn’t just about fixing errors; it’s also about working through a problem methodically. When something goes wrong, developers follow a clear process to understand, isolate, and fix the issue. The following diagram shows a typical debugging workflow that helps programmers identify where a program goes off track and how to bring it back on course.

This flow begins by reviewing the code and understanding what it should do. Then, developers run tests using different inputs and observe what happens. If the output isn’t what they expect, they walk through the logic step by step, often printing out variables to see what’s going on inside the program. By isolating the part of the code that is causing trouble, they can fix it and test it again. This process is repeated until the program works as intended.

Debugging isn’t just for beginners. It’s something all programmers do, from entry-level developers to senior engineers. In fact, the ability to debug well is a sign of strong technical thinking. Professional developers often spend more time reading and improving existing code than writing new lines from scratch. Debugging is also a collaborative process: teams work together to trace errors, share insights, and learn from mistakes. Whether through pair programming, code reviews, or troubleshooting bugs in production, debugging becomes a valuable skill not just for solving problems but also for learning and growing as a programmer.

big idea
Debugging is a skill that combines logic, patience, and detective work. It’s one of the most important parts of being a programmer. Not only does it help you find your mistakes, but it also helps you improve your understanding of a language.

Now that you’ve learned about the different types of errors and how debugging works, let’s apply that knowledge to a simple example. Review the pseudocode below and identify what needs to be fixed so that the program behaves as expected.


Set grade to 85

If grade is less than 60
  Print "Fail"
If grade is greater than or equal to 60
  Print "Fail"

EXAMPLE

This pseudocode is intended to check a student’s grade and print the appropriate message:

Solution:

Both conditions print “Fail,” even when the grade is 85. That’s a logic error. The second condition should print “Pass” instead.


If you found it interesting to break down tasks into step-by-step logic or enjoyed spotting and fixing errors, you are already thinking like a programmer. Skills like writing pseudocode and debugging are not just for coding. These skills are essential in many IT careers, including software development, data analysis, cybersecurity, and DevOps. If this kind of thinking appeals to you, consider taking an introductory programming course, such as Introduction to Python or Introduction to Java. These classes build directly on what you have practiced here and can help you take the next step toward a technical career path.

terms to know
Debugging
The process of finding and fixing problems in code logic or behavior.
Bug
A problem in a program that causes it to crash, behave unexpectedly, or give incorrect results.
Syntax Error
An error that breaks the rules of the programming language, such as missing punctuation or misspelling. These prevent the program from running.
Runtime Error
An error that occurs while the program is running, often caused by unexpected input or impossible operations like dividing by zero.
Logic Error
An error where the program runs but produces the wrong outcome because the logic of the code is incorrect.

summary
In this lesson, in the introduction to programming, you saw that writing instructions a computer can follow is about breaking tasks into clear, exact steps. As you explored pseudocode, you learned how to plan a program in plain language by identifying inputs, outputs, variables, and the right order of actions, while using conditionals and loops to make decisions and repeat tasks. Debugging brought a problem-solving mindset to life, showing how syntax, runtime, and logic errors are found and fixed and how even experienced programmers use patience and detective work to get programs running as intended.

Source: THIS TUTORIAL WAS AUTHORED BY SOPHIA LEARNING. PLEASE SEE OUR TERMS OF USE.

Terms to Know
Bug

A problem in a program that causes it to crash, behave unexpectedly, or give incorrect results.

Conditional

A logic structure that allows a program to make decisions based on whether a statement is true or false.

Debugging

The process of finding and fixing problems in code logic or behavior.

Iteration (Looping)

A process of repeating actions until a condition is met or for a set number of times.

Logic Error

An error where the program runs but produces the wrong outcome because the logic of the code is incorrect.

Programming

Writing instructions for a computer to execute.

Programming Logic

The use of clear, step-by-step instructions to tell a computer exactly what to do and when.

Pseudocode

A way to plan and explain what a program should do using plain language instead of real code.

Runtime Error

An error that occurs while the program is running, often caused by unexpected input or impossible operations like dividing by zero.

Syntax Error

An error that breaks the rules of the programming language, such as missing punctuation or misspelling. These prevent the program from running.

Variable

A container that holds information, such as a number or a word, which a program can remember and use later.