> ## 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 If Statement

The `if` statement in Go is a control flow construct used for conditional execution of code blocks based on the evaluation of a boolean expression.

```go theme={"dark"}
if condition {
    // execution block
}
```

## Technical Characteristics

* **No Parentheses:** The boolean condition does not require enclosing parentheses `()`.
* **Mandatory Braces:** The execution block must be enclosed in curly braces `{}`. Single-line `if` statements without braces are syntactically invalid.
* **Brace Placement:** Due to Go's automatic semicolon insertion (ASI), the opening brace `{` must appear on the same line as the end of the condition. The condition itself may span multiple lines, but placing the opening brace on a new line after the condition's conclusion will result in a compilation error.
* **Strict Boolean Evaluation:** The condition must evaluate strictly to a `bool` type. Go does not support implicit type coercion or "truthiness" (e.g., integers like `1` or `0`, empty strings, or non-nil pointers cannot be evaluated directly as boolean conditions).

## Extended Syntax (`else if` and `else`)

Go supports branching via `else if` and `else` clauses.

```go theme={"dark"}
if conditionA {
    // block A
} else if conditionB {
    // block B
} else {
    // default block
}
```

**Formatting Constraint:** The `else if` or `else` keywords must be placed on the same line as the closing brace `}` of the preceding block. Placing `else` on a new line triggers automatic semicolon insertion after the closing brace, resulting in a syntax error.

## Initialization Statement

Go allows an optional initialization statement to be executed immediately before the boolean condition is evaluated. This is typically a short variable declaration.

```go theme={"dark"}
if initialization_statement; condition {
    // execution block
}
```

**Lexical Scoping Rules:**

1. **Block Scope:** Variables declared within the initialization statement are scoped exclusively to the `if` block, as well as any subsequent `else if` or `else` blocks in the same chain.
2. **Shadowing:** Variables declared in the initialization statement will shadow variables of the same name existing in the outer lexical scope for the duration of the `if` chain.
3. **Scope Termination:** Once execution exits the `if-else` chain, variables declared in the initialization statement go out of scope and are no longer accessible by name. (Note: Variable *lifetime* is determined separately by Go's escape analysis, not strictly by this lexical scope).

<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>
