WeGievU.Com
WeGievU.Com
WeGievU.Com
User :
Pass :
  WeGievU.Com
WeGievU.Com
WeGievU.Com
» E-Learning Room > Asp
WeGievU.Com
Control Structures while 
( 23  Views )

Mon 01-09-2551 Time 12:30
Category: Asp/ WeGievU.Com 0Comments
WeGievU.Com

วนลูบ while

for  เป็นคำสั่งสร้างเงื่อนไขให้ทำงานวนรอบซ้ำๆกัน จนกว่าตัวแปรที่กำหนดจะมีค่าครบตามเงื่อนไข โดยจะนำเอาเรื่องของการกำหนดค่าให้กับตัวแปรหรือAssignment Operators เข้ามาเกี่ยวข้องด้วย  การ Assignment   ค่าให้กับ  Operators ก็คือการสร้างเงื่อนไขและกำหนดค่าให้กับตัวแปรเป็นค่าต่างๆ จนครบที่กำหนด

 

รูปแบบคำสั่ง

Whileเงือนไข

งานที่จะต้องทำ


Wend

ตัวอย่าง

while.asp

<html>
<head>
<title>Gangza</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<%
n = 1
while n <=5
Response.write( n & " WeGiveU <br>")
n = n + 1
wend
%>
</body>
</html>

ผลลัพธ์

1. WeGiveU
2. WeGiveU
3. WeGiveU
4. WeGiveU
5. WeGiveU

คำอธิบาย

กำหนดให้ n มีค่าตั้งแต่ 1 ถึง 5

และให้พิมพ์คำว่า WeGiveU แต่จะมีตัวเลขข้างหน้า ตั้งแต่ 1 จนถึง 5 โดยเว้นบรรทัด

******************************************
ลองดัดแปลงการใช้ดูเอานะครับ


แสดงความคิดเห็น “ Control Structures while   Comment”
WeGievU.Com
WeGievU.Com


Learning
| Tip | Knowledge
Copyright (c) 2010 by Wegiveu.com Team ( We Give Everything )