The complexity is actually either O(n^3) or more likely O(n^2)
as that outer loop is infinite (just keeps going until you escape out - and program ends??) it dont count.
'unprocessed time' isnt specified how it works - if its an interval limiter for some periodic processing (whose processing isnt indicated here) so this appears to be a time loop - so also shouldnt count in processing complexity (which is usually based on processing per 'turn' of the game)
The processing of EVERY unit per tick (which is some turn interval?) and THAT processes comparing with every other unit (for distance tested for some interaction...) that part is O(n^2) for your brute force method.
((then plus whatever else gets done with that distance.... which again is not specified))
---
Simple optimization :
Ive sometimes used a half-table caching where the distance calc is symetrical and I find it once between units and filled both in to the table (distance[j] = distance[j]i] = calculated distance, and use mutated loops (below) to make it O(n*n/2) (it also skips calculating the units distance from itself which is always 0)
for I=0 to totalunits
{
Distance[I][I] = 0 // note- unit always 0 from itself
for J=I+1 to totalunits // note starts at where I is
{
D = calculate_distance(I,J); // whatevere
Distance[I][J] = Distance[J][I] = D;
} // end J loop
} // end I loop
0 1 2 3 4
0 0 * * * *
1 . 0 * * * these traversed and calculated
2 . . 0 * *
3 . . . 0 *
4 . . . . 0
these filled with symetrical data
SO effectively you actually calculate half of what the simple looping does...
I usually use that when the majority of interactions are none (but still need testing for) and the distance winds up being the majority of the processing (Ill use some space-partitioning if the 'unit' count goes high enough to warrant implementing it.
---
Sometimes (depending on the simulation) the interaction between the two units can be carried out once and that half of the table needs no traversal, while other times the interactions are unsymetrical (if the interactions are really sparse, building a list of only those within threshold is also possible - useful if game mechanics require sorting by interaction distance or somesuch)
--------------------------------------------[size="1"]Ratings are Opinion, not Fact