C++ Başka


Diğer Bildirimi

elseKoşul ise yürütülecek bir kod bloğu belirtmek için ifadeyi kullanın false.

Sözdizimi

if (condition) {
  // block of code to be executed if the condition is true
} else {
  // block of code to be executed if the condition is false
}

Örnek

int time = 20;
if (time < 18) {
  cout << "Good day.";
} else {
  cout << "Good evening.";
}
// Outputs "Good evening."

Örnek açıklama

Yukarıdaki örnekte, zaman (20) 18'den büyüktür, bu nedenle koşul false. Bu nedenle elsekoşula geçiyoruz ve ekrana "İyi akşamlar" yazdırıyoruz. Zaman 18'den az olsaydı, program "İyi günler" yazdırırdı.