How do I reset a for-loop while looping through a list? For example, I want the for-loop to reset i.e. (i=0 and j=1) when there are duplicates in a list .
In this piece of code, I want the duplicates removed and the for-loop reset when subsequent entries in the list are equal. For instance, we have
list1 = [east, west, west, east]
I want the resultant list1 to be equal to an empty list.
This is because, When both "west" entries are eliminated, this results in the list updating to [east,east]. Since this is also a duplicate, the result must hence be an empty list [].
j=1;
for (int i=0;i<(list1.size()-1);i++){
if((list1.get(i)==list1.get(j))){
list1.remove(i);
list1.remove(i);
i=0;
j=1;
}else{
j++;
}
}