Інструкція If
Оператор if, також відомий як умовний оператор, — це спосіб виконання блоку коду залежно від умови. Синтаксис оператора if виглядає наступним чином:
if(condition) {
// code to execute
}
Він приймає вираз і виконує блок коду, якщо вираз дорівнює true
.
Наприклад:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 9) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Якщо умова є false
, блок коду ігнорується:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 10) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Can you give me an example of an if statement in JavaScript?
What happens if the condition is false in an if statement?
Can you explain what types of expressions can be used as conditions?
Awesome!
Completion rate improved to 1.59
Інструкція If
Свайпніть щоб показати меню
Оператор if, також відомий як умовний оператор, — це спосіб виконання блоку коду залежно від умови. Синтаксис оператора if виглядає наступним чином:
if(condition) {
// code to execute
}
Він приймає вираз і виконує блок коду, якщо вираз дорівнює true
.
Наприклад:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 9) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Якщо умова є false
, блок коду ігнорується:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 10) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Дякуємо за ваш відгук!