var stark = []; stark.push(1); while(stark.length){ var value = stark[stark.length-1]; if(value>5){ stark.pop(); break; }else{ alert(value); stark.push(value+1); } }