How do I use if statement?

Category: Introduction, viewed: 140 time(s).

The if control statement is used for checking a boolean expression. If the boolean expression has a true value the if block will be executed.

using System;

namespace Kodecsharp.Example.Intro
{
    public class IfDemo
    {
        [STAThread]
        public static void Main(string[] args)
        {
            //
            // Declares a variable i, j, k and assign a value to it.
            //
            int i = 2, j = 10, k = 20;

            // Check if i has the same value with j/
            if (i == j)
            {
                Console.WriteLine("i == j");
            }
            
            // Check if i is less than j or i is less than k.
            if ((i < j) || (i < k))
            {
                Console.WriteLine("i " + i + " is less that j or k");
            }

            // Check to see if i multiplied with j equals to the value of k.
            if (i * j == k)
            {
                Console.WriteLine("i * j = " + (i * j));
            }

            Console.ReadLine();
        }
    }
}
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Our Friends

Network Sites

Statistics

Locations of visitors to this page