> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go Goto Statement

The `goto` statement in Go provides an unconditional transfer of control to a designated, named label within the same function. It alters the sequential execution flow by immediately moving the instruction pointer to the target label.

```go theme={"dark"}
goto LabelName

// ... intermediate code ...

LabelName:
    // execution continues here
```

## Mechanics and Lexical Rules

* **Function Scope:** Labels are strictly function-scoped. A `goto` statement cannot transfer control across function boundaries.
* **Namespace:** Labels exist in their own namespace. A label can share the same identifier as a variable, type, or package without causing a naming collision.
* **Compiler Strictness:** Go enforces strict compilation rules regarding labels. Declaring a label without a corresponding control flow statement (`goto`, `break`, or `continue`) targeting it results in a compile-time error (`label defined and not used`).
* **Case Sensitivity:** Label identifiers are case-sensitive and must conform to standard Go identifier rules (starting with a letter or an underscore).

## Control Flow Restrictions

Go imposes strict lexical scoping restrictions on where a `goto` statement can jump to prevent undefined behavior and uninitialized memory access.

### 1. Bypassing Variable Declarations

A `goto` statement cannot jump over the declaration of a variable into a scope where that variable is accessible. Doing so results in a compile-time error because the variable would be in scope but uninitialized.

**Invalid:**

```go theme={"dark"}
func invalidDeclarationJump() {
    goto Target // Compile error: goto Target jumps over declaration of val
    
    val := 42 
    
Target:
    fmt.Println(val) 
}
```

**Valid:**

```go theme={"dark"}
func validDeclarationJump() {
    var val int
    goto Target 
    
    val = 42 
    
Target:
    fmt.Println(val) // Valid: declaration was not bypassed, only assignment
}
```

### 2. Jumping Into Nested Blocks

A `goto` statement cannot transfer control from outside a lexical block into the interior of that block. You cannot jump into the body of an `if`, `for`, `switch`, or `select` statement from the outside.

**Invalid:**

```go theme={"dark"}
func invalidBlockJump() {
    goto InnerBlock // Compile error: goto InnerBlock jumps into block
    
    if true {
    InnerBlock:
        fmt.Println("Inside conditional block")
    }
}
```

**Valid:**

```go theme={"dark"}
func validBlockJump() {
    if true {
        goto OuterBlock 
    }
    
OuterBlock:
    fmt.Println("Outside conditional block")
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Go Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
