Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Do While...Loop on ASP

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

robinson
Newbie


Posts: 18
Group: Registered
Joined: Sep 2006
Status: Offline
Reputation: 0
Points: 0 (Donate)
Post: #1

Wink Do While...Loop on ASP


Again, we will define a condition and one or more instructions:

Code:
<%
mynumber=0
Do While mynumber<10

    response.write("Hello<HR>")
    mynumber=mynumber+1

Loop
%>


In this example the condition is "mynumber<10" and the instructions defines a response text and an increment of the variable "mynumber". In the example, mynumber will be increased until it gets a value of 10. Then the loop will be abandon. Several instruction may be used within the loop.

Do Until....Loop

Quite similar to the previous one, it also includes a condition and one or more instructions:

Code:
<%
mynumber=0
Do Until mynumber=10

    response.write("Hello<HR>")
    mynumber=mynumber+1

Loop
%>


In this example the condition is "mynumber=10", so mynumber will increased until it is equal to 10, and then the loop will be abandon.

Let's see an example using this Do Until...Loop:

Code:
<%
myfirstnumber=0
mysecondnumber=0

Do Until myfirstnumber=15

     Do Until mysecondnumber=15
              response.write("X")
              mysecondnumber=mysecondnumber+1
     Loop
     Response.write ("<BR>")
     myfirstnumber=myfirstnumber+1
     mysecondnumber=myfirstnumber

Loop

Response.write ("END")
%>


The result of the script is this one:

Quote:
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
END


Select Case....End Select

This is a very useful instruction in case we want to check different values for variable. Lets check an example:

Code:
<%
mynumber=3
Select Case mynumber
   Case 1
       Response.write ("Number 1")
   Case 2
       Response.write ("Number 2")
   Case 3
       Response.write ("Number 3")
   Case 4
       Response.write ("Number 4")
   Case 5
       Response.write ("Number 5")
   Case Else
       Response write ("Mynumber is higher than 5")
End Select
%>


In this example above, we have defined mynumber as 3, so they are executed the instructions following line 8 (in this case only one instruction is executed, but they may be several instructions). Case Else is not necessary.

Let's try a second example:

Code:
<%
username=request.form("username")
Select Case username
   Case "Peter"
       Response.write ("Hello, Peter")
   Case "John"
       Response.write ("Hello, John")
   Case "Joe"
       Response.write ("Hi, Joe")
   Case Else
       Response write ("I do not know you")
End Select
%>


Let's see a different example:

backgroundform.html

Code:
<html>
<head><title>Chose background color</title></head>
<form action="backgroundresponse.asp" method="post">
Which color do you prefer to use as your background?
<BR>
<input type="radio" name="kindofcolor" value="defined" checked>
Defined color
<select name="definedcolor">
<option value="#FFFFFF">White</option>
<option value="#FF0000">Red</option>
<option value="#00FF00">Green</option>
<option value="#0000FF">Blue</option>
</select>
<BR>
<input type="radio" name="kindofcolor" value="custom">
Custom color
<input type="text" size="8" name="mycolor"></input>
<BR><input type="Submit" value="Submit"></input>
</form>
</body>
</html>



backgroundresponse.asp

Code:
<%
kindofcolor=Request.form("kindofcolor")

Select Case kindofcolor
   case "defined"
    colorofbackground=Request.form("definedcolor")
       Select Case colorofbackground
                 case "#FFFFFF"
                      texttoshow="White"
                 case "#FF0000"
                      texttoshow="Red"
                 case "#00FF00"
                      texttoshow="Green"
                 case "#0000FF"
                      texttoshow="Blue"
        End select
   case "custom"
        colorofbackground=Request.form("mycolor")
        texttoshow="Custon color"
End select
%>

<html>
<head><title>Chose background color</title></head>
<body bgcolor="<% =colorofbackground %>">
<center>
<H1><% =texttoshow %></H1>
</center>
</form>
</body>
</html>

23-09-2006 01:25 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Website of the Month

Create-a-Page for Free
SOTM June 2008


Accepting Submissions
for July 2008
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 07-09-2008, 06:30 AM


Copyright © 2002-2008 MyBB Group
Powered By MyBB