---
title: "Why goto should be avoided"
subject: "Computer Programming"
chapter: 5
key: "semester_1/computer_programming:goto-avoided"
source: https://www.bctengineer.com/q/semester_1/computer_programming/goto-avoided
site: BCT Engineering
---

# Why goto should be avoided

Computer Programming · Chapter 5: Control statements

- Asked in: 2069 Chaitra, 1 marks
- Video: [why is it illegal to use "goto"?](https://www.youtube.com/watch?v=AKJhThyTmQw) — Low Level
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/goto-avoided
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-5

## Question

Explain why goto statement should be avoided.

## Short answer

goto should be avoided because it disrupts structured programming, creating tangled spaghetti code that is hard to read, debug, and maintain. Every goto can be replaced with clearer loops and conditional break/continue statements.

## Answer

`goto` jumps unconditionally to a labelled statement.

```c
#include <stdio.h>
int main(void)
{
    int i = 1;
loop:
    if (i <= 3)
    {
        printf("%d ", i);
        i++;
        goto loop;      /* jumps back; same job as a while loop */
    }
    printf("\n");
    return 0;
}
```
It should be avoided because:
- it breaks the structured flow, producing tangled "spaghetti code" that is hard to read and trace;
- programs with `goto` are difficult to debug and maintain;
- any job done by `goto` can be done more clearly with `for`, `while`, `if` and `break`;
- it makes testing and proving correctness harder.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why does goto produce spaghetti code?
   A. It breaks structured flow with unconditional jumps
   B. It uses too much memory
   C. It is slower than loops always
   D. It is not part of C
   Answer: A. Jumps make flow hard to trace. (Key point: Spaghetti code)

2. What can replace goto in programs?
   A. Only recursion
   B. for, while, if and break
   C. Only switch
   D. Nothing can
   Answer: B. Structured statements can do any job of goto. (Key point: Alternatives)

3. Which is a drawback of goto?
   A. Cannot jump backwards
   B. Cannot be compiled
   C. Hard to debug and maintain
   D. Needs a header file
   Answer: C. Programs with goto are difficult to debug and maintain. (Key point: Maintenance)

## Related in other subjects

- [CT secondary should not be kept open](https://www.bctengineer.com/question.md?key=semester_4%2Felectrical_machines%3Act-secondary-open-true-false) — Electrical Machines, chapter 2
- [DC series motor should not start on no-load](https://www.bctengineer.com/question.md?key=semester_4%2Felectrical_machines%3Adc-series-motor-no-load-start) — Electrical Machines, chapter 4
