C++ da Nested If Kullanımı

 Nested If, bir koşulun doğru olup olmadığını kontrol eden bir tür koşuldur ve bir ifade bloğu yürütülür.

Model Yapı:

eğer base_condition doğruysa
// { } bloğunun içindeki her şey yürütülecek
eğer (temel_koşul)
{
    ifade 1..............
    ifade 2 ..............
}

Misal:
// C++ Program demonstrate
// use if-else condition
#include <iostream>
using namespace std;

int main()
{
int a = 7, b = 6;
if (a > b) {
cout << "True" << endl;
}
}

Output: True 

Nested If Nedir?

Aynı kapsamda (aynı kapsam, bir { } bloğunun altında anlamına gelir) bir dizi if bloğu birbiri ardına mevcut olduğunda, bu koşula İç İçe if koşulu denir. İlk koşul True ise, bir sonraki if koşuluna geçeriz ve sonraki koşul, false koşulu elde edene kadar kontrol edilir ve kontrol durur.

Model Yapı
// eğer base_condition doğruysa kontrol base_condition1'e gider
eğer (temel_koşul)
{
    // eğer base_condition doğruysa kontrol base_condition2'ye gider
    eğer(temel_koşul1)
    {
        eğer(temel_koşul2)
            ..........................
        ..........................
    }
}
Misal
// C++ Program to
// Nested-if conditions
#include <iostream>
using namespace std;

int main()
{

int a = 33, b = 21, c = 2;

// if this condition satisfies then
// control goes to next if condition
if (a > b) {
// if this condition also turns out to be
// true then the statements under
// this block will get executed
if (a > c) {
cout << " a en büyüktür" << endl;
}
}
return 0;
}

Output : a en büyüktür


Hiç yorum yok:

Yorum Gönder