DEV Community

Munisa Kuranbekova
Munisa Kuranbekova

Posted on

Else if haqida

Assalomu aleykum! O'tgan safar biz if statement haqida gaplashgan edik. Bu safar ham shunga o'xshash lekin undan ozgina boshqacha bo'lgan mavzu haqida gaplashamiz.
Else if - deyarli if statement bilan bir xil. Ularning bir biridan farqi shundaki else if statementida birinchi if tekshiriladi va birinchi ifga to'g'ri kelmasa keyingi if tekshiriladi.
Kod yozilatotganda bir emas yozayotgan kodingizga mos ravishda bir nechta else if ishlatish mumkin. Kod orqali tushuntiradigan bo'lsak:

#include <iostream>

using namespace std;

int main()
{

int n;

cin >> n;

if(n % 2)
{
cout << n / 2 << endl;
}

else if(n % 3) 
{
cout << n / 3 << endl;
}

else if(n % 5)
{
cout << n / 5 << endl;
}

return 0;
}
Enter fullscreen mode Exit fullscreen mode

yuqorida yozilgan kodni tahlil qiladigan bo'lsak , birinchi ifda biz kiritgan son 2 ga bo'linsa uni 2 ga bo'lib chop etadi. Undan tashqari boshqa shartlarni ham ichiga kirib tekshirib chiqadi va to'g'ri kelganlarini shartini bajarib chop etadi.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay