Assuming
The objective is to drink as much soda as possible, as cheaply as possible per bottle (which means not having more lids left over than necessary)
Then buy
25 soda
And drink them. You now have
25 lids.
Trade in
21 lids, keep 4, get +3 soda, drink them too.
You now have
4+3=7 lids.
Trade them in:
you now have 1 soda. Drink it, or don't.
You now have:
1 lid, and enough money to buy 5 more soda.
If you could
borrow one lid, you could use that to get one more bottle of soda, then return the borrowed lid.
My profit is
If I can borrow a lid: I get to drink 35 bottles for the price of 30, a 16.666% 'profit' margin.
If buy 25, then cannot borrow a lid: I get to drink 29 bottles for the price of 25, a 16% 'profit' margin.
If however, I were buy 30 bottles, only to find that cannot borrow a lid: I would now drink 34 bottles for the price of 30, a 'profit' of only 13.333%. So I don't do that.