If-instructie
Een if-statement, ook wel conditionele instructie genoemd, is een methode om een codeblok uit te voeren op basis van een voorwaarde. De syntaxis van een if-statement is als volgt:
if(condition) {
// code to execute
}
Het neemt een expressie en voert het codeblok uit als de expressie true is.
Bijvoorbeeld:
main.cs
12345678910111213141516using 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"); } } }
Als de voorwaarde false is, wordt het codeblok genegeerd:
main.cs
12345678910111213141516using 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"); } } }
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Can you give me an example of an if statement in JavaScript?
What happens if the condition is false in an if statement?
Can you explain what types of expressions can be used as conditions?
Awesome!
Completion rate improved to 1.59
If-instructie
Veeg om het menu te tonen
Een if-statement, ook wel conditionele instructie genoemd, is een methode om een codeblok uit te voeren op basis van een voorwaarde. De syntaxis van een if-statement is als volgt:
if(condition) {
// code to execute
}
Het neemt een expressie en voert het codeblok uit als de expressie true is.
Bijvoorbeeld:
main.cs
12345678910111213141516using 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"); } } }
Als de voorwaarde false is, wordt het codeblok genegeerd:
main.cs
12345678910111213141516using 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"); } } }
Bedankt voor je feedback!