<script type="text/javascript"> var a = []; for ( var i = 0, n = 0; i < 10; i++, n = i > 5 ? n - 1 : n + 1 ) a.push( n ); alert( a ); </script>