Order orders[] = getUnshippedOrders (); for ( Order o : orders ) { o.ship (); } This reuses existing methods to send outstanding shipments …but there's a problem lurking
Order orders[] = getUnshippedOrders (); for ( Order o : orders ) { o.ship (); } select * from orders where shipment_date is null The data source is almost certainly a SQL query…
select * from orders where shipment_date is null Order orders[] = getUnshippedOrders (); for ( Order o : orders ) { o.ship (); } insert into shipments … update orders … …and each shipment will modify the database
Avoiding crimes against SQL String || concatenation Use bind variables SQL in loops 1 statement, many rows Batch processing Same table many times SQL analytics 1 2 3