# Conditional

The conditional (a.k.a. `if`) is one of the most fundamental items in programming logic. Parenthesis on the if **are optional**. Due to this, braces are required around the code block. The rationale for this was that omitting braces can result in difficult to debug, critical bugs, as Apple has shown us\[citation-needed].

## Definition

The general syntax is the following:

```
if <condition> {
    [statement_1]
} [else if <condition> {
    [statement_2]
} ...][else {
    [statement_3]
}]
```

## Examples

```swift
if 1 == 1 {
    print "1 is in fact 1"
} else {
    print "Your universe is borked"
}
```

Additionally, an arbitrary amount of `else if` blocks can be supplied:

```go
var num = Math.rand(3);

if num == 1 {
    print "Random number was 1"
} else if num == 2 {
    print "Random number was 2"
} else if num == 3 {
    print "Random number was 3"
} else {
    print "Random number was #{num}"
}
```

## Scoping

Ifs, like all other code-blocks in Cheddar are **block scoped**. The condition of the if is evaluated in the parent's context, meaning the new scope will only be created, once the condition has been validated and the code-block is ready to execute.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cheddar.vihan.org/docs/control-flow/conditional.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
