Advertisement
Advertisement
//C# - if statement program
using System;
class A
{
public static void Main()
{
int a = 100, b = 50;
float f1 = 2.5f, f2 = 5.9f;
//If there is just one statement associated with an if block then
//no curly braces are needed
if(a>b)
Console.WriteLine("100 is greater than 50");
//If there is more than one statement associated with an if block then
//curly braces are needed
if(b<a)
{
Console.WriteLine("50 is less than 100");
Console.WriteLine("Second statement to execute");
}
//You may add curly braces even with a single statement associated with an if block
if(f1>f2)
{
Console.WriteLine("2 is greater than 4");
}
//This statement associated with any if block
Console.WriteLine("Statement outside an If Statement");
}
}
100 is greater than 5
50 is less than 100
Second statement to execute
Statement outside If Statement
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement