C# nested if-else Statement :

nested if-else Statement :

Sometimes the programming logic in a program or an application needs to be represented by multiple if-structures contained in each other. We call them nested if or nested if-else structures.

Example :

  1. /* Description: simple nested if-else program */
  2. using System;
  3. namespace DemoProgramming
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int first = 5,second = 3;
  10. if (first == second)
  11. {
  12. Console.WriteLine("These two numbers are equal.");
  13. }
  14. else
  15. {
  16. if (first > second)
  17. {
  18. Console.WriteLine("The first number is greater.");
  19. }
  20. else
  21. {
  22. Console.WriteLine("The second number is greater.");
  23. }
  24. }
  25. Console.ReadKey();
  26. }
  27. }
  28. }

Output :

C Sharp Language simple nested if-else program

Next Update

Loading...

Currently, we are working on other servers, but soon we update our website with new content. So, stay tuned we are back soon with new content.

Free Courses