Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems understanding basic when and for looping

Status
Not open for further replies.

estesflyer

Programmer
Dec 19, 2000
284
US
here is a script that I was supposed to write after reading some tutorials at webmonkey, which werent that great at all! If someone could plz explain this script line by line and tell me how it works I would really be greatful!!

<script language=&quot;javascript&quot;>
<!--
var height = prompt(&quot;How high do you want the grid? (1-10 is good)&quot;,&quot;10&quot;);

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

var a_line;

var new_window =
window.open(&quot;top.html&quot;,&quot;looper&quot;,&quot;width=400,height=400&quot;);

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

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

{

a_line = &quot;&quot;;

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

{

a_line+=&quot;x&quot;;

}

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

}

//-->



Also, if you know of any sites that talk about the for and when loops, I would really be thankful for that also!!

- Rusty
 
<!--
var height = prompt(&quot;How high do you want the grid? (1-10 is good)&quot;,&quot;10&quot;);
//set height equal to whatever the user types in

var width= prompt(&quot;How wide do you want the grid? (1-10 is good)&quot;,&quot;10&quot;);
//set width equal to whatever the user types in

var a_line;
//define a variable a_line

var new_window = window.open(&quot;top.html&quot;,&quot;looper&quot;,&quot;width=400,height=400&quot;);
//open a new window, with a reference of new_window
//(now you can talk to it - new_window.whatever)

new_window.document.writeln(&quot;<h1>A Grid</h1>&quot;);
//write HTML inside the new window

for (height_loop = 0; height_loop < height; height_loop++)
{
//declare a loop - this code will be executed as many times as
//the variable height declares

a_line = &quot;&quot;;

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

{
//declare a loop - this code will be executed as many times as
//the variable width is declared
a_line+=&quot;x&quot;;

}

new_window.document.writeln(a_line + &quot;<br>&quot;);
//write a line break after each row is printed
}

//-->
</script> jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top