4.1.The if Statement

The if Statement

An if statement allows you to take different paths of logic, depending on a given condition. When the condition evaluates to a boolean true, a block of code for that true condition will execute. You have the option of a single if statement, multiple else if statements, and an optional else statement.

Listing 3-1. forms of the if statement (Single Selection)

using System;

namespace CSharp
{
        class if_Selection
        {
                static void Main(string[] args)
                {
                        float score;
                        Console.Write("Enter Score: ");
                        score = float.Parse(Console.ReadLine());
                        if (score >= 50)
                                Console.WriteLine("Passed");
                        Console.ReadKey();
                }        
        }
}

Example 1: Windows Forms Application:

Yes No Suggest edit
Suggest Edit