Nested loops are frequently (but not always) bad practice, because they're frequently (but not always) overkill for what you're trying to do. In many cases, there's a much faster and less wasteful way to accomplish the goal you're trying to achieve.
For example, if you have 100 items in list A, and 100 items in list B, and you know that for each item in list A there's one item in list B that matches it, (with the definition of "match" left deliberately obscure here), and you want to produce a list of pairs, the simple way to do it is like this:
for each item X in list A:
for each item Y in list B:
if X matches Y then
add (X, Y) to results
break
With 100 items in each list, this will take an average of 100 * 100 / 2 (5,000) matches
operations. With more items, or if the 1:1 correlation is not assured, it becomes even more expensive.
On the other hand, there's a much faster way to perform an operation like this:
sort list A
sort list B (according to the same sort order)
I = 0
J = 0
repeat
X = A[I]
Y = B[J]
if X matches Y then
add (X, Y) to results
increment I
increment J
else if X < Y then
increment I
else increment J
until either index reaches the end of its list
If you do it this way, instead of the number of matches
operations being based on length(A) * length(B)
, it's now based on length(A) + length(B)
, which means your code will run much faster.