编辑器加

<script language="javascript">
<!--

//用for计算1+2+3+....+20
var num = 0;
var total = 0;
for(num = 0; num < 21; num++)
{
total = total+num;

}
document.write("--------- 总------: "+total);

//用while计算1+2+3+....+20
var num = 0;
var total = 0;
while( num < 21)
{
total=num+total; num++;

}
document.write("总和: "+total);

//用do...while计算1+2+3+....+20
var num = 0;
var total = 0;
do
{
total = total+num; num++;

}
while(num< 21 );
document.write("--------- 总------: "+total);

-->
</script>


载中...

posted on 2012-03-02 15:46  彭蓉  阅读(571)  评论(0)    收藏  举报