您的位置:寻梦网首页编程乐园JavaScriptJavascript入门到精通
Javascript 入门到精通

第 1 天 第 2 天 第 3 天 第 4 天 第 5 天
第6页:嵌套循环
作者:Thau!

这是程序:



var height = prompt("How high do you 
want the grid? (1-10 is good)","10");

var width= prompt("How wide do you want 
the grid? (1-10 is good)","10");

var a_line;

var new_window = 
window.open("/webmonkey/98/04/files1a
/grid.html","looper","width=400,height=400");

new_window.document.writeln("<h1>A Grid</h1>");

for (height_loop = 0; height_loop 
< height; height_loop++) 

{    

    a_line = "";

    for (width_loop = 0; 
width_loop < width; width_loop++)

    {

        a_line+="x";

    }

    new_window.document.writeln
(a_line + "<br>");

}

在请求高及宽后,打开一新窗口,并为它写一个头,进入for循环。第一个for循环设a_line=“”。试一下不用该行做一下本例,看看会发生什么。在初始化a_line后,程序进入下一个for循环,当宽达到所需值后,建立X`S行并将它显现在新窗口中。这些将发生height次。

好,现在你的任务:看一下这个循环练习并亲自试着在看源码前写一个。


Page 1: 第四课介绍
Page 2: 循环介绍
Page 3: 循环的密码
Page 4: 再谈 WHILE循环
Page 5: For 循环
Page 6: 嵌套循环
Page 7: 循环练习
Page 8: 数组
Page 9: 数组和循环
Page 10: 文件目标模块中的数组
Page 11: 函数
Page 12: 无参数函数
Page 13: 参数及返回值
Page 14: 多于一个参数的函数


本内容由搜狐网站(www.sohoo.com.cn)提供。