Efficient if loops in C#
Posted by Gizmosis350k
Last Updated: April 28, 2012
  2053

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ch04Ex02
{
    class Program
    {
        static void Main(string[] args)
        {
            string comparison;
            Console.WriteLine("Enter a number:");
            double var1 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Enter another number:");
            double var2 = Convert.ToDouble(Console.ReadLine());
            if (var1 < var2)
            {
                comparison = "less than";
            }
            else if (var1 == var2)
            {
                comparison = "equal to";
            }
            else
                comparison = "greater than";
            
            Console.WriteLine("The first number is {0} the second number.", comparison);
            Console.ReadKey();
        }
    }
}



A simple if loop embedded here tells if the two numbers you entered are greater than, less than or equal to each other.
This "else if" structure allows the program to not indent too far, by giving each argument its own set of curly brackets. @.@
   
  
 
 
   

 
 
Efficient ...... hmmm gona try it.
 good stuff.
 
Yeah, this way of declaring if statements is better for your code and i easier to read ^_^
 
its not if loops its a if statement!

Great progress!!!
 
Thanks for the correction - waiting on the revamp to "clean" my blogs
 
ok