Jump to content

deleting item from array in the same iteration?


dyei nightmare

Recommended Posts

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? 

 

Link to comment
Share on other sites

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 by dyei nightmare
Link to comment
Share on other sites

 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!!!!!!!!!!!!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...