<commit_before>---
type: doc
layout: reference
category: "Syntax"
title: "Returns and Jumps: break and continue"
---

# Returns and Jumps

Kotlin has three structural jump expressions:

* *return*{: .keyword }. By default returns from the nearest enclosing function or [anonymous function](lambdas.html#anonymous-functions).
* *break*{: .keyword }. Terminates the nearest enclosing loop.
* *continue*{: .keyword }. Proceeds to the next step of the nearest enclosing loop.

All of these expressions can be used as part of larger expressions:

<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
val s = person.name ?: return
```
</div>

The type of these expressions is the [Nothing type](exceptions.html#the-nothing-type).

## Break and Continue Labels

Any expression in Kotlin may be marked with a *label*{: .keyword }.
Labels have the form of an identifier followed by the `@` sign, for example: `abc@`, `fooBar@` are valid labels (see the [grammar](grammar.html#labelReference)).
To label an expression, we just put a label in front of it

<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
loop@ for (i in 1..100) {
    // ...
}
```
</div>

Now, we can qualify a *break*{: .keyword } or a *continue*{: .keyword } with a label:

<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
loop@ for (i in 1..100) {
    for (j in 1..100) {
        if (...) break@loop
    }
}<commit_msg>Fix broken hash link in returns<commit_after>---
type: doc
layout: reference
category: "Syntax"
title: "Returns and Jumps: break and continue"
---

# Returns and Jumps

Kotlin has three structural jump expressions:

* *return*{: .keyword }. By default returns from the nearest enclosing function or [anonymous function](lambdas.html#anonymous-functions).
* *break*{: .keyword }. Terminates the nearest enclosing loop.
* *continue*{: .keyword }. Proceeds to the next step of the nearest enclosing loop.

All of these expressions can be used as part of larger expressions:

<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
val s = person.name ?: return
```
</div>

The type of these expressions is the [Nothing type](exceptions.html#the-nothing-type).

## Break and Continue Labels

Any expression in Kotlin may be marked with a *label*{: .keyword }.
Labels have the form of an identifier followed by the `@` sign, for example: `abc@`, `fooBar@` are valid labels (see the [grammar](grammar.html#label)).
To label an expression, we just put a label in front of it

<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
loop@ for (i in 1..100) {
    // ...
}
```
</div>

Now, we can qualify a *break*{: .keyword } or a *continue*{: .keyword } with a label:

<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
loop@ for (i in 1..100) {
    for (j in 1..100) {
        if (...) break@loop
    }
}
{'fraction_non_alphanumeric': 0.13948717948717948, 'fraction_numerical': 0.010256410256410256, 'mean_word_length': 4.079861111111111, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6251611', 'n_tokens_mistral': 951, 'n_tokens_neox': 899, 'n_words': 363}