C# IF, Switch, For, While Loop Statements



You will get a better understanding as we go through the various statements which are available in C#.

if Statement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemoIfStatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Int32 value = 11;
            if (value < 10)
            {
                Console.WriteLine("Value is less than 10");
            }
            else
            {
                Console.WriteLine("Value is greater than 10");
            }
            Console.ReadKey();
        }
    }
}

Switch Statement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemoSwitchStatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Int32 value = 11;
            switch (value)
            {
                case 1:
                    Console.WriteLine("Value is 1");
                    break;
                case 2:
                    Console.WriteLine("Value is 2");
                    break;
                default:
                    Console.WriteLine("value is different");
                    break;
            }
        }
    }
}

While Statement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpCodeWhileStatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Int32 value = 3, i = 0;
            while (i < value)
            {
                Console.WriteLine(i);
                i = i + 1;
            }
            Console.ReadKey();
        }
    }
}

0 Comment's

Comment Form

Submit Comment