actionscript 3 - AS3 Array 1 to 100 -
i'm having trouble finding way array doesn't make me type numbers , example : (i found code online)
var array:array=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] var odds:array=[], evens:array=[], odds_sum:int=0, evens_sum:int=0 ; for(var i:int = 0; < array.length; i++){ if(array[i] % 2 == 1){ odds.push(array[i]); odds_sum += array[i]; } else { evens.push(array[i]); evens_sum += array[i]; } } trace(odds); trace(odds_sum); trace(evens); trace(evens_sum);
i wanted code trace numbers between 1 , 100 (including 1 , 100) don't have type them down. solving appreciated
your question ambiguous , if need numbers between 1 , 100
for(var i:int = 1; <= 100; i++){ trace(i); }
or if want them in array
var arr:array = new array(); for(var i:int = 1; <= 100; i++){ arr.push(i); }
or if want odd , numbers in separate array
var odds:array = new array(); var evens:array = new array(); for(var i:int = 1; <= 100; i++){ if(i%2==0) evens.push(i); else odds.push(i); }
where array odds/even have appropriate numbers between 1 , 100.
Comments
Post a Comment