# Stops & Exits

The `stop` or `exit` effect is used to terminate a section of code, or an entire structure. This is really useful for when you don't need to run more code, and can tell Skript to stop or ignore the rest of a section.

{% hint style="info" %}
`Stop` and `exit` are actually the same effect, except they are conventionally worded differently for different tasks.

`stop` usually terminates all code within a structure, while `exit` commonly only escapes or terminates a loop or section, but leaves higher instances running.
{% endhint %}

Syntax (following the conventional uses explained above):\
`stop [trigger]`\
`exit [(%integer%|a|the|this)] (section|loop|conditional)[s]`

{% hint style="info" %}
These also usually allow for using a guard clause. Not sure what a guard clause is? See the [Guard Clauses page](broken://pages/JRfzRrb142X10vxik3S7).
{% endhint %}

Example 1 (`stop`):

\[use on chat and if muted, tell is mute and stop. else set format => gclause]

{% code overflow="wrap" lineNumbers="true" %}

```python
if {cooldown} < now:
  send "Please wait before doing this!" to player
  
else:
  set {cooldown} to now
  give player 1 of diamond
  send "You were given a diamond!" to player
```

{% endcode %}

If the cooldown is still in effect, the code doesn't need to run (or even read) the next lines. Using a `stop` there tells Skript that it's done all it needs to do, and can disregard everything from that instance.

{% code overflow="wrap" lineNumbers="true" %}

```python
if {cooldown} < now:
  send "Please wait before doing this!" to player
  stop

set {cooldown} to now
give player 1 of diamond
send "You were given a diamond!" to player
```

{% endcode %}

Example 2 (`exit`):

For this example, here's a script that gives the player 10 random items from the `{customItems::*}` list.

{% code overflow="wrap" lineNumbers="true" %}

```python
loop (shuffled {customItems::*}):
  if loop-iteration < 10:
    give player loop-value

send "You were just given 10 random custom items!" to player
```

{% endcode %}

{% hint style="info" %}
Not sure what the `shuffled` expression is? See the [Lists page](broken://pages/Dk3Isjuz3VObBUbxQ8nh).
{% endhint %}

The `{customItems::*}` list could contain a lot more than ten items, it could even contain hundreds of items. That means the loop will run many more times than needed! The entire list will be looped through, even if the item for that iteration is not given. By exiting the loop, only the first 10 iterations are run, then it backs out of the loop and skips straight to sending the message.

{% code overflow="wrap" lineNumbers="true" %}

```python
loop (shuffled {customItems::*}):
  give player loop-value
  if loop-iteration >= 10:
    exit 1 loop

send "You were just given 10 random custom items!" to player
```

{% endcode %}


---

# 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://x8ight.gitbook.io/syntask/limiters/terminators/stops-and-exits.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.
