Printing data in a row of a table

hey folks,
i m trying to create a loop which is going good and printing in a table. but i want to print it all in just one row.(horizontal) for now this is my code

<html>
	<head>
		<title>For:Loop</title>
	</head>
	
	<body>
	<script type="text/javascript">
	var i = 0;
	for (i=0;i<=10;i++){
	document.write("<table width=50 border=1><tr><td>" +i+ "</td><tr></table>")
	}
	</script>
	</body>
</html>

its very confusing with that variable name. can u explain me. wht happens or better yet have a variable name more good

wel for wht i can see is u have re declare variable from <table><tr> to </tr></table>. but when i name it any other variable. say i make newhtml to n or t. it doesn’t work.

Edit: i was able to fix it. i was printing the old newhtml doc. :stuck_out_tongue: sorry my bad.
thanks though!

Will this do it for you

<html>
    <head>
        <title>For:Loop</title>
    </head>
    
    <body>
    <script type="text/javascript">
    var i = 0;
    var newhtml = "<table width=50 border=1><tr>";
    for (i=0;i<=10;i++){
        newhtml = newhtml + "<td>" +i+ "</td>"
    }
    newhtml = newhtml + "</tr></table>"
    document.write(newhtml);
    </script>
    </body>
</html>

newhtml is simply a javascript variable which I am using in forming a string of html which is eventually written.

The javascript is forming html for a table, <table>, with one row, <tr>, and one cell, <td>, for each value of the loop.

so newhtml will end up with them string

<table width=50 border=1><tr><td>0</td><td>0</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td></tr></table>

Before the loop starts we put in “<table width=50 border=1><tr>” which starts the table and the row.

Then we do the loop which adds each of the cells.

Finally after the loop we close the row and table “</tr></table>”

Hope that makes things clearer.