Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen else Keyword | Kontrollstrukturen
C# Grundlagen

else Keyword

Swipe um das Menü anzuzeigen

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

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:

S3C7
question mark

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

Wählen Sie die richtige Antwort aus

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 7

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

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

main.cs

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:

S3C7
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 7
some-alt