> For the complete documentation index, see [llms.txt](https://hanuce.gitbook.io/javascript-egitimi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanuce.gitbook.io/javascript-egitimi/donguler/break-continue-label.md).

# break - continue - label:

Standart kullanımda döngüler koşul kontrol edildiğinde **`true`** ise döngüye girer, kod bloklarını döngü bloğunun sonuna kadar yürütür ve tekrar koşulu kontrol eder. Bu böyle devam eder...

Fakat sizler kod bloklarının herhangi bir noktasında döngüyü sonlandırmak, kodları atlayarak sonraki tekerrüre geçmek veya daha üst bloktaki döngüyü kontrol etmek isteyebilirsiniz.

## `break` Komutu

Bu komutu daha önce **`switch - case`** yapısında görmüştük. **`break`** komutu döngü bloklarını sonlandırmak için kullanılabilir. Buna döngüler de dahil. Örnek.

{% code lineNumbers="true" %}

```javascript
for (let i = 0; ; i++) { //normalde sonsuz döngü
    alert(i);
    if (i == 2) break; // i=2 olunca döngü kırılır.
}
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
let i = 0;
while (true) { //normalde sonsuz döngü
    i++;
    alert(i);
    if (i == 3) break; // i=3 olunca döngü kırılır.
}
```

{% endcode %}

**`if`** ile kullanmak şart değildir.

{% code lineNumbers="true" %}

```javascript
for (let i = 0; ; i++) { // normalde sonsuz döngü
    alert(i);
    break;
    alert('Bu uyarılar ekranda görülmeyecek');
    alert('Çünkü döngü kırıldı');
}
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
let i = 0;
while (true) { //normalde sonsuz döngü
    i++;
    alert(i);
    break;
    alert('Bu uyarılar ekranda görülmeyecek');
    alert('Çünkü döngü kırıldı');
}
```

{% endcode %}

**`break`** komutu sonsuz döngü yapılarıyla sık kullanılır.

## `continue` Komutu

**`continue`** komutu bir döngünün doğrudan bir sonraki döngü adımına (tekerrüre) geçmesini sağlar. **`continue`** komutundan sonraki kodlar yürütülmez bir sonraki döngü adımı (tekerrür) başlar. Örnek.

{% code lineNumbers="true" %}

```javascript
for (let i = 1; i < 4 ; i++) {
    if (i == 2) continue; // 2.Döngü uyarısı continue sebebiyle alınamaz.
    alert(`${i}. Döngü`);
}
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
for (let i = 1; i < 4 ; i++) {
    if (i < 3) continue; // 1.Döngü ve 2.Döngü uyarısı alınamaz.
    alert(`${i}. Döngü`);
}
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
let i = 0;
while (i < 3) {
  i++;
  if (i == 2) continue;
  alert(`${i}. Döngü`)
}
```

{% endcode %}

Bu komutlar virgül operatörleri ile kullanıldığında yazım hatası verir. Bu sebeple virgül veya koşullu operatör ile kullanılmaz.

## `:` Etiket (label) Tanımlayıcısı

**`break`** ve **`continue`** bulunduğunuz bloğu kontrol eder, peki ya daha üst blokta olan döngüleri alt bloktan nasıl kontrol ederiz. Bunun için **`:`** tanımlayıcısı kullanılır. Örnek.

{% code lineNumbers="true" %}

```javascript
ust_dongu: for (let i = 1; i < 4; i++) {
    for (let j = 1; j < 4; j++) {
        alert(`${i}. Döngünün içindeki ${j}. Döngü`);
        if (j == 3) break ust_dongu;
    } 
}
// veya etkiketi bir satır yukarı tek başına da koyabilirsiniz.
ust_dongu:
for (let i = 1; i < 4; i++) {
    for (let j = 1; j < 4; j++) {
        if (i == 2) break ust_dongu;
        alert(`${i}. Döngünün içindeki ${j}. Döngü`);
    } 
}
```

{% endcode %}

**`while`** döngüsü ile de kullanılabilir. Örnek.

{% code lineNumbers="true" %}

```javascript
let i = 0, j = 0;
ust_dongu:
while (i < 4) {
    i++;
    while (j < 4) {
        j++;
        alert(`${i}. Döngünün içindeki ${j}. Döngü`);
        if (j == 3) break ust_dongu;
    }
}
```

{% endcode %}

Aynı tanımlamalar **`continue`** ile de yapılabilir. Bu durumda sonraki döngü (tekerrür) için geçeceği yeri belirtmiş oluruz. Örnek.

{% code lineNumbers="true" %}

```javascript
ust_dongu:
for (let i = 1; i < 4; i++) {
    for (let j = 1; j < 4; j++) {
        if (j == 2) continue ust_dongu;
        alert(`${i}. Döngünün içindeki ${j}. Döngü`);
    } 
}
```

{% endcode %}

Farklı örnek olarak.

{% code lineNumbers="true" %}

```javascript
ust_dongu:
for (let i = 1; i < 4; i++) {
    for (let j = 1; j < 4; j++) {
        alert(`${i}. Döngünün içindeki ${j}. Döngü`);
        if ( confirm('Döngüyü bitirmek istiyor musunuz?') ) break ust_dongu;
    }
}
```

{% endcode %}

Etiket tanımlayıcıları **`break`** ve **`continue`** komutları ile birlikte **döngüler** için kullanılabilirler.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://hanuce.gitbook.io/javascript-egitimi/donguler/break-continue-label.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.
