Chapter 17
The Dual-Alternative Decision Structure
17.1 The Dual-Alternative Decision Structure
In contrast to the single-alternative decision structure, this type of decision control structure includes a statement or block of statements on both paths.
If Boolean_Expression evaluates to true, the statement or block of statements 1 is executed; otherwise, the statement or block of statements 2 is executed.
The general form of the C# statement is
if (Boolean_Expression) {
A statement or block of statements 1
}
else {
A statement or block of statements 2
}
In the next example, the message “You are an adult” is displayed when the user enters a value greater than or equal to 18. The message “You are underage!” is displayed otherwise.
![](https://cdn.statically.io/img/static.packt-cdn.com/products/9781836205630/graphics/my_exercise_header.png)
int age;
Console.Write("Enter your age: ");
age = Convert.ToInt32(Console.ReadLine());
if (age >= 18) {
Console.WriteLine("You are an adult!");
}
else {
Console.WriteLine("...