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