Net-informations.com
SiteMap  | About    

if else statements

The conditional statement IF-ELSE is using for check the conditions that we provided in the head of if statement and making decision based on that condition. The conditional statement examining the data using comparison operators as well as logical operators.

vb.net
  If [Condition] Then
	Statement
  Else
	Statement

End If

C#
  if (condition)
	statement;
  else

statement;

If the given condition is true then the control goes to the body of if block , that is the program will execute the code within if block. If the condition is false then the control goes to next level , that is if you provide else block the program will execute the code block of else statement, otherwise the control goes to next line of code.

The else statement is optional , so yo can use if statement without else statement.

vb.net
  If [Condition] Then
	Statement

End If

C#
  if (condition)

statement;

If you want to check more than one conditions then you can use else-if statement .

vb.net
  If [Condition] Then
	Statement
  ElseIf [Condition] Then
	Statement
  Else
	Statement

End If

vb.net
  if (condition)
	statement;
  else if (condition)
	statement;
  else

statement;

The following ASP.NET program declare and initialize values to two numbers , num1 and num2 and then check which is greater using if statement.

Default.aspx

  

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
		<br />
		<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.