To optimize loops, avoid unnecessary computations by using conditions inside the loop. For example, skip any zero-value discounts in a discount array before adding them to the total. This reduces processing time: for (int i = 0; i < discounts.length; i++) { if (discounts[i] == 0) continue; totalDiscount += discounts[i]; }.