The difference is that code blocks à foreach or while are executed within a single frame, just as are functions. All those blocks theoretically represent a line of a script, and OFP always parses one line at once.
So OFP takes the same time for executing
myVar = 1
as for
myVar = 1; mySecondVar = 2; myThirdVar = 3
or for
{myArray = myArray + [_x]} forEach [1,2,3,4,5]
Of course, the longer a line, the more lag will appear ingame on the long run. But if used wisely and sparely, you can get pretty good results.