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
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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");
}
}
}
}
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:
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 3. Hoofdstuk 7
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.