Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele If Statement | Control Structures
C# Basics

bookIf Statement

An if statement, also known as conditional statement, is a method of executing a block of code based on a condition. The syntax of an if statement is the following:

if(condition) {
    // code to execute
}

It takes an expression and executes the code block if the expression is true.

For example:

main.cs

main.cs

copy
12345678910111213141516
using 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"); } } }

In case the condition is false the code block is ignored:

main.cs

main.cs

copy
12345678910111213141516
using 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"); } } }
question mark

What is the output of the following code:

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 5

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Awesome!

Completion rate improved to 1.59

bookIf Statement

Pyyhkäise näyttääksesi valikon

An if statement, also known as conditional statement, is a method of executing a block of code based on a condition. The syntax of an if statement is the following:

if(condition) {
    // code to execute
}

It takes an expression and executes the code block if the expression is true.

For example:

main.cs

main.cs

copy
12345678910111213141516
using 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"); } } }

In case the condition is false the code block is ignored:

main.cs

main.cs

copy
12345678910111213141516
using 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"); } } }
question mark

What is the output of the following code:

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 5
some-alt