else 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
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"); } } } }
The following diagram explains the flow of if else
statement:
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 7
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 1.59
else Keyword
Svep för att visa menyn
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
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"); } } } }
The following diagram explains the flow of if else
statement:
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 7