dyei nightmare Posted September 15, 2018 Share Posted September 15, 2018 just wanna know how can be deleted an item from an array in the same iteration, this doesnt work. int miarray[] = {1,2,3,4,5,6,8,9,10}; foreach(int i; miarray) { if(somecondition == 0){ pop(miarray,i); } } since aparently you cant reference the array itself from inside... how do you delete an index in the same iteration? Quote Link to comment Share on other sites More sharing options...
dyei nightmare Posted September 16, 2018 Author Share Posted September 16, 2018 (edited) ah the only thing that works is in for() and with removevalue... think it is because foreach cant update the array lenght per iteration??? this works: int myarray[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13}; int myarrlen = len(myarray); for(int i=0; i<myarrlen;i++){ if(i%2==0){ removevalue(myarray,i); } } but should be a way to delete an item inside the same foreach somehow, but how? Edited September 16, 2018 by dyei nightmare Quote Link to comment Share on other sites More sharing options...
dyei nightmare Posted September 16, 2018 Author Share Posted September 16, 2018 i[]@miarray = {33,16,21,88,90}; i@length = len(@miarray); for(int h=0; h<@length; h++){ i@remover = @miarray[h]; removevalue(@miarray,@remover); } ahhhh now i found the real question... why this doesnt remove everything in array? it just leaves 2 items, is not removing everything but.. whhhhhhyyyy!!! it doesn make senseeeeeeeeeee!!!!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
dyei nightmare Posted September 16, 2018 Author Share Posted September 16, 2018 (edited) aaaaaahhhh solveeed!!! now i understand why, when removevalue is executed, the array updates inmediatelly, and the next iteration, jumps any elements. but it is logic if i think about it... Edited September 16, 2018 by dyei nightmare Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.