Conditional Statements 1
Conditional Statements 1
If the first condition is not met, you can use the else if
statements that follow to test more conditions (lines 5 to 12). There
can be multiple else if statements. Finally, you can use the else
statement (lines 13 to 16) to execute some code if none of the
preceding conditions are met. To fully understand how the if
statement works, add the following code to the Main() program in the
VSC template
int userAge;
Console.Write("Please enter your age: ");
userAge = Convert.ToInt32(Console.ReadLine());
else
{
Console.WriteLine("Congratulations!");
Console.WriteLine("You may sign up for the event!");
}
Console.Read();
The program first prompts the user for his age and stores the
result in the userAge variable.
Next the statement if (userAge < 0 || userAge > 100)