I am iterating with a for loop through a map of phone details and removing those older than 14 days. However unless I use a try catch the loop crashes, I assume its because I am reducing the amount of items in the map and then it dies when trying to count to the original number of items. 
Is there any way around this without resorting to a try catch?
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			Is there any way around this without resorting to a try catch?
			
				B4X:
			
		
		
		For I = 0 To phoneMap.Size - 1
       
        'get the key out
        Dim Key As String= phoneMap.GetKeyAt(I)
        Dim  Value As String= phoneMap.GetValueAt(I)
        Log("read for date " & Value)
        Dim comma As Int = Value.IndexOf(",")
        Dim dateSaved  As String = Value.SubString(comma +1)
        'PROBLEM! You have a loop through a list but the list is shrinking as items are deleted from it, therefore you run out of items and the system crashes, ie: it wants to loop to 14 but you only have 7 in the list because you have just deleted out 7. fixed with below sort of
       
    Try  'nasty coding but wtf
        If (dateSaved <= date14DaysAgo) Then
                Log(" delete this entry too old " & dateSaved)
                phoneMap.Remove(Key)
        End If
    Catch
    End Try
Next 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		