General Concepts of Programming Methodology

Logical Errors

Concepts of Programming Methodology

Programming is basically solving a particular problem by giving coded instructions to the computer. Furthermore, the whole scenario of the programming cycle involves writing, testing, troubleshooting, debugging, and maintaining a computer program. Moreover, a good program should have clarity and simplicity of expressions, should make use of the proper name of identifiers, contain comments, and have a proper indentation. Besides, it should be free from all types of errors such as syntax errors, runtime errors, and logical errors.

Programming Process Cycle

The steps of programming are as follows:

Writing

This step involves writing the desired output of the code. besides, drawing a flowchart depicting all the steps from beginning to end. Then the programmer writes the first copy of the code on the programming software.

Testing

This step is about testing the code against the test cases. If the output is according to desired test cases, the code is correct.

Troubleshooting

After testing the program we perform the error correction in this step.

Debugging

It is the process of finding the exact location of the error in the code. Errors can be of different types such as syntax errors, runtime errors, and logical errors.

Running

After all these steps the program is run to get the desired output.

Running and Debugging Programs

After writing a program, we need to run and test the program. Testing means running each instruction and checking the validity of output. Furthermore, after testing we can know about the errors in the program. Besides, then we can solve and correct these errors and make the program error-free. We can do this by debugging the program. This means finding the location of the error and then resolving it by making necessary changes. There can be several types of errors therefore, running and debugging programs are necessary.

Browse more Topics Under General Concepts of Programming Methodology

Logical/Semantic Error

If your program is syntax free it will compile successfully. But, if the logic is incorrect it is not necessary that you get the desired output. Therefore, such errors are logical or semantic errors. Usually, such errors are indicated during run time. Since the program has no syntax errors, therefore, it runs successfully. But, it is not necessary that you get the expected output. Hence, in such cases, we have to check the program for logical errors. Thus, we can say that logical error is a type of runtime error.

For example,

                    
int a=10;

if (a%10=0)

{

printf("divisible by 10");

}

In this program logic, the user needs to check divisibility by 10. But, in the ‘if’ condition instead of using ‘==’ it is ‘=’ which is the assignment operator. Therefore, we need the ‘==’ operator to check if the remainder is equal to 0 or not.

Runtime Error

These types of errors are detected during the runtime. Moreover, such errors cause unusual termination of the program. Some examples of such errors are as follows:

  • dividing a number by 0
  • infinite loop
  • wrong input by the user

Difference between Syntax and Logical Errors

Syntax Error Logical Error
  • This is the error that occurs due to the violation of syntax rules of a particular programming language. this usually happens when we change the intended syntax of writing the sequence of tokens or characters.
  • This type of error causes unexpected and unusual results for the program.
  • The program terminates due to such errors and cannot execute successfully until we rectify it.
  • It does not cause termination of the program abnormally.
  • The cause is the fault in the program syntax.
  • The cause is the fault in the logic or algorithm.
  • The compiler indicates the error and its location itself in compiled languages.
  • The programmer has to find the error himself.
  • It is easier to detect a syntax error.
  • On the other hand, finding a logical error is comparatively more difficult.

Frequently Asked Questions (FAQs)

Q1. What is the running and debugging of programs?

A1. Running is to run the program to get the output. While debugging is finding the location of an error.

Q2. Name the types of errors.

A2. Types of errors are as follows:

  • Syntax error
  • Logical/Semantic error
  • Runtime error

Q3. What is a logical error?

A3. We can define a logical error as a bug in the logic or algorithm of a program.

Q4. What is the other name for logical error?

A4. Semantic Error

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

avatar
  Subscribe  
Notify of

Customize your course in 30 seconds

Which class are you in?
No thanks.