What Are Logic Errors?

Tim Buchalka's Learn Programming Academy
A free video tutorial from Tim Buchalka's Learn Programming Academy
Professional Programmers and Teachers - 1.1M students
4.5 instructor rating • 52 courses • 1,158,223 students

Lecture description

In this video we discuss logic errors and give a simple example.

Learn more from the full course

Beginning C++ Programming - From Beginner to Beyond

Obtain Modern C++ Object-Oriented Programming (OOP) and STL skills needed for game, system, and application development.

41:29:30 of on-demand video • Updated January 2021

  • Learn to program with one of the most powerful programming languages that exists today, C++.
  • Obtain the key concepts of programming that will also apply to other programming languages
  • Learn Modern C++ rather than an obsolete version of C++ that most other courses teach
  • Learn C++ features from basic to more advanced such as inheritance and polymorphic functions
  • Learn C++ using a proven curriculum that covers more material than most C++ university courses
  • Learn C++ from an experienced university full professor who has been using and teaching C++ for more than 25 years
  • Includes Quizzes, Live Coding Exercises, Challenge Coding Exercises and Assignments
English In this video, we'll talk about logic errors and why they can happen. Logic errors, or errors or bugs in your code that cause your program to run incorrectly. Logic errors are mistakes made by a programmer. Sometimes the mistakes are careless of the time. Some mistakes are because the programmers have incomplete or incorrect information. Other times mistakes occur when one programmer modifies another programmer's code to fix or add something, and they introduce an error as they do this. There are many, many causes for logic errors. It doesn't matter what the cause is though, they need to be corrected. We need to test our code and debug it to find incorrect errors. Suppose we have a program that determines if a person can vote in an election and you must be 18 years old or older to vote. We haven't talked about if statements yet in this class. But they're very intuitive and I'm sure you'll follow this little piece of code. First, we test to see if the age is greater than 18. If it is, then we execute the code that's inside those curly braces. Do you see the error. It’s pretty easy to see it here because the code is isolated, and I told you there was an error. However, in reality, there's much more code typically involved. In this may just be a small part of a much larger program. The problem with this code is that the test conditions should be greater than or equal to 18 or greater than 17, either one will work. As it's written now, 18 year old would not be able to vote. We'll talk about testing throughout the course in the context of learning c++ and best practices. Well, that wraps up this section. Next, you can take the section quiz and attempt the challenge exercise and see how you do. I'm sure you'll do great. If you have any questions, please post them to the course forum.