var i = 1000; var count = 0; while(i <= 2000) { if (i % 2 == 0 && i % 100 !=0 || i % 400 == 0) { document.write(i, " "); count++; if(count % 4 == 0) { document.write("<br/>"); } } i++; }