Choice statements
if assertion
if~else assertion
- ikki yoki undan ko’p execution pathlarni tanlaydi
if (a>=0)
cout << "optimistic";
if (a<0)
cout << "unfavourable";
If assertion
- if expression is true, execute statement1
if(expression)
{(physique)
statement1
}
if (a>=0)
cout << "optimistic";
-
do not use
semi-colon (;)
after if(expression)- Agar semi-colon ishlatilsa, if assertion mustaqil bo’lib qoladi.
- Agar if assertionda faqat bitta assertion bo’lsa
{}
qo’yilmaydi.
int a,b,c;
cin >> a >> b >> c;
int max = a > b ? a : b;
if (max > c)
cout << max << endl;
- Agar if assertion
situation
bajarilmasa output da hech narsa chiqmaydi. -
If assertion faqat o’zidan keyingi birinchi turgan
cout
ga ta’sir qiladi. -
Use == (Realtion operator), do not use = (Task)
if (staff == '10')
cout << "Lions" << endl;
not
if (staff = '10')
// consequence staff is 10
If-else assertion
- If expression is true, execute statement1. If false, execute statement2
- Syntax
if(expression)
{(physique)
statement1
}
else
{(physique)
statement2
}
if (sonpercent2 == 0)
cout << "even" << endl;
else
cout << "odd" << endl;
- if assertion comprises one other if assertion (together with if-else assertion)
if (a>=0)
if (xpercent2 ==0)
cout << "optimistic even quantity" << endl;
else
cout << "optimistic odd quantity" << endl;
else-if assertion
if (a>='A' && a<='Z')
cout << "Higher-case" << endl;
else if (a>='a' && a<= 'z')
cout << "Decrease-case" << endl;
else if (a>='0' && a<='9')
cout << "Quantity" << endl;
else
cout << "Others" << endl;