# İf &	Switch	yapısı

* Belirlenen şartlara göre karar alan yapılardır.&#x20;
* Kararlar, şartın **true** veya **false** olmasına göre alınır.

## if

```dart
void main(){

  int yas = 17;
  String isim = "mehmet";

  //Örnek 1

  if ( yas >= 18){
    print("Reşitsiniz");
  }

  //Örnek 2 else

  if ( yas >= 18){
    print("Reşitsiniz");
  }else{
    print("Reşit değilsiniz");
  }

  //Örnek 3

  if (isim == "ahmet"){
    print("Merhaba ahmet");
  }else{
    print("Tanınmayan kişi");
  }

  //Örnek 4

  if (isim == "ahmet"){
    print("Merhaba ahmet");
  }else if ( isim == "mehmet"){
    print("Merhaba mehmet");
  }else{
    print("Tanınmayan kişi");
  }

  //Örnek 5 çoklu şart and

  String kullaniciAdi = "adminx";
  int sifre = 12345;

  if (sifre == 12345 && kullaniciAdi == "admin"){// true and true : true
    print("Hoşgeldiniz");
  }else{
    print("Hatalı giriş");
  }

  //Örnek 6 çoklu şart or

  int sinif = 10;

  if (sinif == 9 || sinif == 10 || sinif == 11 || sinif == 12){
    print("AYT sınavına hazırlanabilirsiniz");
  }

  //Örnek 7 kısaltma

  int a = 10;
  int b = 14;

  if ( a == b)  print("Eşit"); else  print("Eşit Değil");


}
```

{% code title="if Dört İşlem" %}

```dart
import 'dart:io';

void main(){


  print("Toplama (1)");
  print("Çıkarma (2)");
  print("Çarpma (3)");
  print("Bölme (4)");

  int tercih = int.parse(stdin.readLineSync());

  print("Birinci sayıyı giriniz");
  int sayi1 = int.parse(stdin.readLineSync());

  print("İkinci sayıyı giriniz");
  int sayi2 = int.parse(stdin.readLineSync());

  if (tercih == 1){
    print("Toplama : ${sayi1+sayi2}");
  }else if (tercih == 2){
    print("Çıkarma : ${sayi1-sayi2}");
  }else if (tercih == 3){
    print("Çarpma : ${sayi1*sayi2}");
  }else if (tercih == 4){
    print("Bölme : ${sayi1/sayi2}");
  }

}
```

{% endcode %}

{% file src="/files/-MX92kkzMNqgKfkxTcsT" %}
if Alan Hesaplama
{% endfile %}

## Switch

* else if yapısının daha pratik kullanımıdır.&#x20;
* Case denilen durumlar sağlanırsa kod çalışır.

```dart
void main() {
  int x = 5;

  switch (x) {
    case 1:
      {
        print("x 1 'e eşittir");
      }
      break;

    case 2:
      {
        print("x 2 e eşittir");
      }
      break;

    default:
      {
        print("x 1 ve 2 e eşit değildir");
      }
  }
}
```

```dart
void main() {
  int gun = 3;
  switch (gun) {
    case 1:
      {
        print("Pazartesi");
      }
      break;

    case 2:
      {
        print("Salı");
      }
      break;

    case 3:
      {
        print("Çarşamba");
      }
      break;

    case 4:
      {
        print("Perşembe");
      }
      break;

    case 5:
      {
        print("Cuma");
      }
      break;

    case 6:
      {
        print("Cumartesi");
      }
      break;

    default:
      {
        print("Böyle bir gün yok");
      }
      break;
  }
}
```

```dart
import 'dart:io';

void main(){

  print("Toplama (1)");
  print("Çıkarma (2)");
  print("Çarpma (3)");
  print("Bölme (4)");

  int tercih = int.parse(stdin.readLineSync());

  print("Birinci sayıyı giriniz");
  int sayi1 = int.parse(stdin.readLineSync());

  print("İkinci sayıyı giriniz");
  int sayi2 = int.parse(stdin.readLineSync());

  switch (tercih){
    case 1 : {print("Toplama : ${sayi1+sayi2}");}break;
    case 2 : {print("Çıkarma : ${sayi1-sayi2}");}break;
    case 3 : {print("Çarpma : ${sayi1*sayi2}");}break;
    case 4 : {print("Bölme : ${sayi1/sayi2}");}break;
    default: {print("Böyle bir işlem yok");}break;
  }

}

/* >ÇIKTI<

Toplama (1)
Çıkarma (2)
Çarpma (3)
Bölme (4)

*/
```


---

# 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://haluk-hackali.gitbook.io/flutter-dart-notes/dart/dart-notlari/if-and-switch-yapisi.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.
