Конструкция if..else

Последнее обновление: 29.04.2024

C

C++

C#

Dart

F#

JavaScript

Kotlin

Python

Rust

C

int n = 21;
     
if(n > 22) 
{
    printf("n > 22 \n");
}
else if (n < 22)
{
    printf("n < 22 \n");
}
else
{
    printf("n == 22 \n");
}

C++

#include <iostream> 

int main()
{
    int n {21};
    if (n > 22)
    {
        std::cout << "n > 22" << std::endl;
    }
    else if (n < 22)
    {
        std::cout << "n < 22" << std::endl;
    }
    else
    {
        std::cout << "n == 22" << std::endl;
    }

    // if-else с инициализацией переменной
    int a {5};
    int b {3};
    if(int c {a - b}; a > b)
    {
        std::cout << "a + b = " << c << std::endl;
    }
    else
    {
        std::cout << "a - b = " << c << std::endl;
    }
}

C#

int n = 21;
     
if(n > 22) 
{
    Console.WriteLine("n > 22");
}
else if (n < 22)
{
    Console.WriteLine("n < 22");
}
else
{
    Console.WriteLine("n = 22");
}

Dart

void main() {
	int n = 21;
	if(n > 22){
		print("n > 22");
	}
	else if(n < 22){
		print("n < 22");
	}
	else{
		print("n = 22");
	}
}

F#

let n = 21
     
if n > 22 then 
    printfn "n > 22"
elif n < 22 then
    printfn "n < 22"
else
    printfn "n = 22"

Получение результата из if..then

let a = 21
let b = 22
let res = if(a > b) then 1 elif(a < b) then -1 else 0
printfn "%d" res

JavaScript

let n = 21;
     
if(n > 22) {
    console.log("n > 22");
}
else if (n < 22){
    console.log("n < 22");
}
else{
    console.log("n == 22");
}

Kotlin

fun main() {
    val n = 21
    if(n > 22) {
        println("n > 22")
    }
    else if(n < 22){
        println("n < 22")
    }
    else{
        println("n = 22")
    }
}

Получение результата из if..else

fun main() {
    val a = 21
    val b = 22
    val res = if(a > b) 1 else if(a < b) -1 else 0
    println(res)    // -1
}

Python

n = 21
if n > 22:
    print("n > 22")
elif n < 22:
	print("n < 22");
else:
	print("n = 22");

Получение результата из if..else

a = 21
b = 22
res = 1 if(a > b) else -1
print(res)

Rust

fn main(){
  
    let n = 21;
    if n > 22 {
        println!("n > 22")
    }
    else if n < 22 {
        println!("n < 22")
    }
    else{
        println!("n = 22")
    }
}

Получение результата из if..else

fn main(){
  
    let a = 21;
    let b = 22;
    let res = if a > b {1} else {-1};
    println!("{}", res);
}
Помощь сайту
Юмани:
410011174743222
Перевод на карту
Номер карты:
4048415020898850