www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help With Nested Loops..

  1. #1
    Join Date
    Oct 2013
    Posts
    8

    Help With Nested Loops..

    Hi everyone, I'm trying to use a nested Loop that emulates a Grid of 100 rows and 10 Columns. And use a Javascript document.write() to display the row number and column number for every cell in the grid.

    I've kind of got an idea of what's going on but just need help tweaking it to get it to work properly..

    Var RowNum = 1;
    Var ColNum = 1;

    DO Until RowNum >= 100

    DO Until ColNum >= 10

    Document.Write("Row:" + RowNum + " Column:" + ColNum);
    ColNum = ColNum + 1;

    Loop


    RowNum = RowNum + 1;

    LOOP


    Any help would be greatly appreciated. Thanks everyone.

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    Two loops, using document.write. I used a table to align things better if you don't mind :P

    Code:
    <!DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="utf-8" />
    		<title></title>
    	</head>
    	<body>
    
    		<table border="1">
    
    		<script type="text/javascript">
    
    			var
    				RowNum,
    				ColNum;
    
    			for (RowNum = 1; RowNum <= 100; ++RowNum) {
    				document.write('<tr>');
    				for (ColNum = 1; ColNum <= 10; ++ColNum) {
    					document.write('<td>Row:' + RowNum + ' Column:' + ColNum + '</td>');
    				}
    				document.write('</tr>');
    			}
    
    		</script>
    
    		</table>
    
    	</body>
    </html>
    Last edited by bionoid; 11-08-2013 at 02:13 PM.
    JavaScript: Learn | Validate | Compact

  3. #3
    Join Date
    Oct 2013
    Posts
    8
    Quote Originally Posted by bionoid View Post
    Two loops, using document.write. I used a table to align things better if you don't mind :P

    Code:
    <!DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="utf-8" />
    		<title></title>
    	</head>
    	<body>
    
    		<table border="1">
    
    		<script type="text/javascript">
    
    			var
    				RowNum,
    				ColNum;
    
    			for (RowNum = 1; RowNum <= 100; ++RowNum) {
    				document.write('<tr>');
    				for (ColNum = 1; ColNum <= 10; ++ColNum) {
    					document.write('<td>Row:' + RowNum + ' Column:' + ColNum + '</td>');
    				}
    				document.write('</tr>');
    			}
    
    		</script>
    
    		</table>
    
    	</body>
    </html>
    Thank you very much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles