网站制作学习网经验与学习→正文:asp,php,js循环比较
字体:

asp,php,js循环比较

经验与学习 2010/4/7 14:51:15  点击:不统计

转www.载for网站制作学习asp必.cn究

在asp,php以及javascript中都有不止一种的循环,下面对三种语言的循环进行比较,列出来方便记忆和应用.
首先是for循环
asp中的for循环举例如下
<%
for foraspcn = 1 to 10 Step 2
response.write foraspcn
Next
%>
输出13579,如果没有step 2 输出 12345678910.中间循环可以用exit for结束循环
php中的for循环
<?
for($foraspcn = 1; $foraspcn<11;$foraspcn++)
{
echo $foraspcn;
}
?>
输出12345678910.中间循环可以用break;结束循环
javascript中的for循环
<script language="javascript">
<!--
for (foraspcn = 1;foraspcn<11 ;foraspcn++ )
{
document.write(foraspcn);
}
-->
</script>
输出12345678910,中间循环可以用exit;来结束循环
www.forasp.cn原创,转载请注明!
其次是(do)while循环
asp中的while循环
<%
foraspcn = 1
While foraspcn<11
response.write foraspcn
foraspcn = foraspcn + 1
wend
%>
输出 12345678910,中间没有退出
asp中do while loop循环
<%
Do While(foraspcn<11)
response.write foraspcn
foraspcn = foraspcn + 1
loop
%>
输出 12345678910,中间退出用exit do
php中的while循环
<?
while($forasp<11)
{
echo $forasp;
$forasp++;
}
?>
输出 12345678910,中间退出用break
php中的do while循环
<?
do
{
echo $forasp;
$forasp++;
}
while($forasp<11)
?>
输出 12345678910,中间退出用break
javascript 中的while循环
<script language="javascript">
<!--
forasp =1;
while(forasp < 11)
{
document.write (forasp);
forasp++;
}
-->
</script>
输出 12345678910,中间退出用exit;
javascript中的do while循环
<script language="javascript">
<!--
forasp =1;
do
{
document.write (forasp);
forasp++;
}
while(forasp < 11)
-->
</script>
输出 12345678910,中间退出用exit;

还有其它一些独立的循环,在这里也列出来
php中的foreach循环,和javascript中的for-in循环,这两种循环有着相似之处
php的foreach循环:
<?php
$forasp = array("f","o","r","a","s","p",".","c","n");
foreach($forasp as $word)
{
echo $word;
}
?>
输出forasp.cn,中间运行时可以退出,退出用break;
javascript中的for-in循环
<script language="javascript">
<!--
var t;
var forasp = new Array("f","o","r","a","s","p","c","n");
for (t in forasp)
{
document.write(forasp[t]);
}
-->
</script>
输出forasp.cn,中间运行时可以退出,退出用break;
以上便是常用的循环,以及循环的举例.努力学习中.....www.forasp.cn原创转载请注明


本文原载于www.forasp.cn

·上一篇:系统优化批处理 >>    ·下一篇:光纤故障网站访问速度减慢 >>
推荐文章
最新文章