# 1.12 Switch

C++ dilinde **switch** ifadesi, bir değişkenin değerine göre farklı kod bloklarının çalıştırılmasını sağlayan bir kontrol yapısıdır. Özellikle bir değişkenin birden fazla olası değerini kontrol etmek istediğimizde **if-else** yapısına alternatif olarak kullanılabilir.

**Temel Yapı**

**switch** ifadesi, bir değişkenin belirli değerlerini kontrol eder. Her bir değeri kontrol etmek için **case** anahtar kelimesi kullanılır. Eğer belirlenen bir case durumu doğruysa, o duruma karşılık gelen kod bloğu çalıştırılır. **break** ifadesi, switch bloğunun dışına çıkmak için kullanılır. Eğer break kullanılmazsa, kontrol akışı sonraki case'lere geçer (bu duruma "fall-through" denir).

```cpp
#include <iostream>
using namespace std;

int main() {
    int gun = 3;

    switch (gun) {
        case 1:
            cout << "Pazartesi" << endl;
            break;
        case 2:
            cout << "Salı" << endl;
            break;
        case 3:
            cout << "Çarşamba" << endl;
            break;
        case 4:
            cout << "Perşembe" << endl;
            break;
        case 5:
            cout << "Cuma" << endl;
            break;
        case 6:
            cout << "Cumartesi" << endl;
            break;
        case 7:
            cout << "Pazar" << endl;
            break;
        default:
            cout << "Geçersiz gün" << endl;
            break;
    }

    return 0;
}
```

**Önemli Noktalar**

1. **Değişken Türü**: Switch ifadesi genellikle tamsayı (int) ve karakter (char) türlerinde kullanılır.
2. **case**: Her bir case, kontrol edilecek değeri belirtir. Bir case bloğunda kod çalıştıktan sonra, eğer break ifadesi yoksa, kontrol akışı sonraki case'lere geçer.
3. **default**: Hiçbir case durumu sağlanmadığında çalıştırılacak kod bloğunu tanımlar. **default** durumu isteğe bağlıdır.

**Örnek: Not Kontrolü**

Aşağıdaki örnekte, bir notun harf karşılığını kontrol eden bir switch ifadesi gösterilmektedir:

```cpp
#include <iostream>
using namespace std;

int main() {
    char not = 'B';

    switch (not) {
        case 'A':
            cout << "Mükemmel!" << endl;
            break;
        case 'B':
            cout << "Çok iyi!" << endl;
            break;
        case 'C':
            cout << "İyi!" << endl;
            break;
        case 'D':
            cout << "Geçer!" << endl;
            break;
        case 'F':
            cout << "Kalır!" << endl;
            break;
        default:
            cout << "Geçersiz not!" << endl;
            break;
    }

    return 0;
}
```


---

# 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.yavuzlar.org/egitim/c-plus-plus/2.0-fonksiyonlar/1.12-switch.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.
