Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0076 Nested if statement

You can nest if statements as follows: using System; class Program { static void Main(string[] args) { int i = 5; if (i > 0) { Console.WriteLine("more than 0"); if (i > 3) { Console.WriteLine("more than 3"); } else { Console.WriteLine("less than 3"); } } } } The output: more than 0 more than 3