DEV Community

Mahamadjon000
Mahamadjon000

Posted on

1

else if

else if - используется когда нужно проверить несколько условий последовательно но выполнять только одно из них.

Пример кода:

#include <iosream>

using namespace std;

int main()
{
int score = 85;

if (score >= 90) 
{
    cout << "Отлично." << endl;
} 
else if (score >= 75) 
{
    cout << "Хорошо." << endl;
}
 else if (score >= 50) 
{
    cout << "Удовлетворительно." << endl;
} 
else 
{
    cout << "Неудовлетворительно." << endl;
}

return 0;
}
Enter fullscreen mode Exit fullscreen mode

В этом примере программа проверяет каждое условие по очереди. Как только одно из условий true код выполняется остальные условия уже не проверяются.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more