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

bookelse Keyword

There is an else keyword which can be used for executing a block of code if the condition is not met.

Here is an example where we output specific text if the condition isn't met:

main.cs

main.cs

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

The following diagram explains the flow of if else statement:

question mark

What keyword is used for executing a piece of code if condition is not met in a conditional statement?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 7

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

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

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

bookelse Keyword

Pyyhkäise näyttääksesi valikon

There is an else keyword which can be used for executing a block of code if the condition is not met.

Here is an example where we output specific text if the condition isn't met:

main.cs

main.cs

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

The following diagram explains the flow of if else statement:

question mark

What keyword is used for executing a piece of code if condition is not met in a conditional statement?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 7
some-alt