asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Programming Languages Primer > While Loops

ASP.NET Programming Languages Primer


The while statement executes embedded statements if, and as long as, a condition is true.

while ( condition ) {
   ... statements ...
}
  C# VB JScript

A while statement is executed as follows:

  • The condition is evaluated.
  • If the condition is true, the embedded statements are executed.
  • Thereafter, control is passed back to the beginning of the while statement, and the processs is repeated as long as the condition is true.
  • When the condition returns false, the loop ends and control is passed to the statement after the while block.

The below example demonstrates use of a while loop to repeatedly render an HTML block, increasing the font size with each pass thru the loop.

 Show me 

Below are links to further code examples that illustrate using the while loop in ASP.NET web forms.

SqlCommand ExecuteReader Example
Run Sample | View Source
Retrieving the Attributes Collection of a Web Control
Run Sample | View Source
More ...
Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note