if/else Statement Can Have One or More Statements in Body

The if/else statement can be used to execute a single statement in both the if and the else part, or to execute a block of statements.  A block of statements can be executed if curly braces ({, }) are used.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Example 1 - block of statements
if (age >= 50)
{
    Console.WriteLine("Hey, you should consider joining AARP!");
    DisplayDetailsOfAARPMembership();
}
else
{
    Console.WriteLine("You're still a young pup");
    DisplayInfoAboutVideoGames();
}
 
// Example 2 - single statements
if (airfare < 850.00)
    BookTickets();
else
    PlanARoadTrip();
 
// Example 3 - mixed
if (married)
{
    KeepPlaceClean();
    RaiseKids();
    LearnInterpersonalSkills();
}
else
    PlayVideoGames();