top of page

Goto Statement in C

  • Writer: Siddharth Sharma
    Siddharth Sharma
  • Oct 8, 2025
  • 1 min read
  • goto statement C में एक jump statement है जो program के execution flow को control करता है। यह किसी specific label पर jump करता है जिसे programmer define करता है.

  • Label एक identifier होता है जिसमें आख़िर में colon (:) लगता है, जहाँ program control jump करेगा.

  • इस statement का use nested loops से बाहर निकलने, error handling, या complex control flow simplify करने में किया जाता है लेकिन code readability खराब कर सकता है, इसलिए इसका ज्यादातर इस्तेमराल avoid किया जाता है.


Syntax

Syntax of the goto statement
Syntax of the goto statement

Example

goto statement program
goto statement program

Output:Program control jumped to label skip.इसमें अगर n की value 0 है तो goto statement "skip" label पर jump कर देता है, और बीच का printf statement skip हो जाता है.


Important Notes

  • goto का improper use spaghetti code (complex, tangled control flow) पैदा कर सकता है, जिससे debugging मुश्किल हो जाती है.

  • इसे सावधानी से, विशेष परिस्थितियों में ही उपयोग करना चाहिए जैसे nested loops से बाहर निकलना या error handling.

  • Modern programming में इसे generally discouraged माना जाता है और structured alternatives (loops और conditionals) prefer किए जाते हैं.


Summary Table

Feature

Explanation

Purpose

Program control को किसी label तक jump करना

Syntax

goto label_name; ... label_name: statement;

Usage

nested loops से बाहर निकलने, error handling

Caution

Code readability और debugging hard बना सकता है

The goto statement is a powerful but risky feature in C, meant for specific control flow needs but mostly avoided for cleaner and maintainable code.

 
 
 

Comments


bottom of page