Ключове слово else
Існує ключове слово else
, яке можна використовувати для виконання блоку коду, якщо умова не виконана.
Синтаксис:
if(expression)
{
// code
}
else
{
// code
}
Приклад:
main.cs
12345678910111213141516171819using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int x = 5; int y = 7; if(x > y) { Console.WriteLine("x is greater than y"); } else { Console.WriteLine("x is equal or less than y"); } } } }
Наступна діаграма пояснює потік оператора if-else:
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 3. Розділ 7
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Suggested prompts:
Can you explain how the if-else statement works in more detail?
Can you provide a code example using the else keyword?
What does the diagram illustrate about the if-else flow?
Awesome!
Completion rate improved to 1.59
Ключове слово else
Свайпніть щоб показати меню
Існує ключове слово else
, яке можна використовувати для виконання блоку коду, якщо умова не виконана.
Синтаксис:
if(expression)
{
// code
}
else
{
// code
}
Приклад:
main.cs
12345678910111213141516171819using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int x = 5; int y = 7; if(x > y) { Console.WriteLine("x is greater than y"); } else { Console.WriteLine("x is equal or less than y"); } } } }
Наступна діаграма пояснює потік оператора if-else:
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 3. Розділ 7