DEV Community

Cover image for C++ Nested if...else
Islamali Akhmadjanov
Islamali Akhmadjanov

Posted on

5

C++ Nested if...else

Assalamu aleykum xurmatli dasturchi bugun siz bilan C++ dasturlash tilida Nested if - ichma ich if ni kirib chiqamiz.

Ba'zan biz boshqa if ichida yani bitta if ** iborasidan foydalanishimiz kerak. Bu ichki o'rnatilgan **if iborasi sifatida tanilgan.

Buni if iboralarining bir nechta qatlami sifatida tasavvur qiling. Birinchi, tashqi if gap, uning ichida esa boshqa, ichki if gap bor.
Uning sintaksisi:

// outer if statement
if (condition1) {

  // statements

  // inner if statement
  if (condition2) {
    // statements
  }
}
Enter fullscreen mode Exit fullscreen mode

Eslatmalar:

  • Agar kerak bo'lsa, ichki if iborasiga else va else if iboralarini qo'shishimiz mumkin.

  • Ichki if iborasi tashqi else yoki else if iboralari (agar mavjud bo'lsa) ichiga ham kiritilishi mumkin.

  • Biz if iboralarining bir nechta qatlamlarini joylashtirishimiz mumkin.

Misol uchun:

#include <iostream>
#include <cmath>
#include <iosmanip>
using namespace std;

int main()
{

  int son;
  cin >> son;

  if(son > 0)
  {
    if(son % 2 == 0)
    {
      cout << "Musbat juft son";
    }
    else
    {
      cout << "Musbat toq son";
    }
  }
  else
  {
    if(son % 2 == 0)
    {
      cout << "Manfiy juft son";
    }
    else
    {
      cout << "Manfiy toq son";
    }
  }


  return 0;
}
Enter fullscreen mode Exit fullscreen mode

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (1)

Collapse
 
jurabek777 profile image
jurabek777

perfect explanation

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay