DEV Community

Munisa Kuranbekova
Munisa Kuranbekova

Posted on

If statement haqida

Assalomu aleykum! Bugun biz C++ dasturidagi if statement haqida gaplashamiz.
Ko'pchilik bilsa kerak , if ingliz tilida agar degan ma'noni anglatadi. If ishlatilayotganda unda shart e'lon qilinadi. Yani kod orqali tushuntiriladigan bo'lsa:

#include <iostream>

using namespace std;
int main()
{

int son;

cin >> son;

if(son > 0)
{
cout << son << endl;
}

return 0;
}
Enter fullscreen mode Exit fullscreen mode

Yuqoridagi kod run qilinsa "son"ga saqlagan o'zgaruvchimiz noldan katta bo'lsa chop etiladi.

  • Agar bergan shartimiz bajarayotgan amalimizga to'g'ri kelmasa if shunchaki ishlamaydi va hech narsa chop etilmaydi.

    Bundan tashqari "yoki" ya'ni ifning else degan qismi ham mavjud. Hozir aytganimdek else yoki degan ma'noni anglatadi.

#include <iostream>

using namespace std;
int main()
{

int son;

cin >> son;

if(son > 0)
{
cout << son << endl;
}

else
{
cout << " none " << endl;
} 

return 0;
}
Enter fullscreen mode Exit fullscreen mode

shu kodda ifdan so'ng else qismi ham yozildi. Shartimizda "son" nomli o'zgaruvchi 0 dan katta bo'lsa o'sha sonning o'zi chop etlishi zarur edi. Ammo biz kiritgan son 0 dan kichik bo'lsa , else qismi ishlaydi va consolega "none" chop etiladi.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay