Net-informations.com
SiteMap  | About    

for loop

For Loops statement, which allows code to be repeatedly executed. In ASP.NET programming sometimes you have to faces situation to repeat a task for several times or you have to repeat a task till you reach a condition, in these situations you can use loop statements to achieve your desired results.

In VB.NET the FOR NEXT Loop , execute the loop body (the source code within For ..Next code block) to a fixed number of times.

vb.net
  For var=[startValue] To [endValue] [Step]
   [loopBody]

Next [var]

  var		: The counter for the loop to repeat the steps.
  starValue	: The starting value assign to counter variable .
  endValue	: When the counter variable reach end value the Loop will stop .

loopBody : The source code between loop body

C#
  for(initialization; condition; step)

statement

  initialization	: Initialize the value of variable.
  condition		: Evaluate the condition

step : Step taken for each execution of loop body

The following ASP.NET example declare two variables startVal and maxVal and then assign the values 1 and 10 respectively and display the number 1 to 10 using for loop.

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.