# Strange bug in my for loop?

**URL:** https://forum.kirupa.com/t/strange-bug-in-my-for-loop/262891
**Category:** web dev
**Created:** [June 10, 2008, 8:55pm UTC](https://forum.kirupa.com/t/strange-bug-in-my-for-loop/262891 "2008-06-10T20:55:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BuG56](https://avatars.discourse-cdn.com/v4/letter/b/c57346/32.png) [@BuG56](https://forum.kirupa.com/u/BuG56)
#### Post date: [June 10, 2008, 8:55pm UTC](https://forum.kirupa.com/t/strange-bug-in-my-for-loop/262891/1 "2008-06-10T20:55:38Z")

</div>

Hello, all. I’m developing something for IE and something is awry with my loop. I have a table which contains a 4 column header, one of those columns containing an “add row” button which calls addRow();. This adds another row right under it with a blank column(blank space under the add row button) and three inputs. The function is generic to work with any amount of columns, since I will be using it on multiple tables. Take a look:

```auto

function addRow(obj) //obj refers to the button "Add Row"
            {
                var colnum = obj.parentNode.parentNode.parentNode.children[1].children.length; //input.td.tr.tbody.the first coulumns length
                alert(colnum); // A quick check to see if the value is correct, this works
                var temptr = document.createElement('tr'); //the new tr is created
                var tempAddrowtd = document.createElement('td'); //the blank space is created
                temptr.appendChild(tempAddrowtd); //the blank space is appended as the first column of the tr
                for(i=0;i<colnum;i++); //the loop is set to execute once for each column that exists
                {
                    alert("loop running."+i); //again, another check to ensure the function is called
                    var temptd = document.createElement("<td>"); //td is created
                    var tempinput = document.createElement("<input>"); //input is created
                        tempinput.type="text"; //input type is set
                    temptd.appendChild(tempinput); //input is appended to td
                    temptr.appendChild(temptd); //td is appended to tr
                }
                obj.parentNode.parentNode.parentNode.appendChild(temptr); //final tr, which should be full after loop, is appended to the body.
            }

```

Now I don’t see anything really wrong with this code, but for some reason, only one column results from the loop. Even though the declaration in the for loop clearly states i=0, and the colnum check clearly states that colnum is 4. The loop is run once. I tried alerting i’s value inside the loop and the very first (and last) value is always 4. What gives?!

Thanks for your help.

---

<div class="post-metadata">

### Author: ![BuG56](https://avatars.discourse-cdn.com/v4/letter/b/c57346/32.png) [@BuG56](https://forum.kirupa.com/u/BuG56)
#### Post date: [June 10, 2008, 10:18pm UTC](https://forum.kirupa.com/t/strange-bug-in-my-for-loop/262891/2 "2008-06-10T22:18:38Z")

</div>

By god I’m stupid. :

```auto

for(i=0;i<colnum;i++);
{

```

\*\*\*\*\*\*\* semicolon. Go about your lives people, sorry about that!
