Boriel Basic Forum
WHILE Loop vs FOR/NEXT Loop - Printable Version

+- Boriel Basic Forum (https://forum.boriel.com)
+-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://forum.boriel.com/forumdisplay.php?fid=16)
+---- Thread: WHILE Loop vs FOR/NEXT Loop (/showthread.php?tid=2004)



WHILE Loop vs FOR/NEXT Loop - RandomiserUsr - 2022-03-12

Hi, quick question:


Programming styles aside which performs better at run time, WHILE or FOR/NEXT ?

I will guess with both are the same? :-)

Thanks


RE: WHILE Loop vs FOR/NEXT Loop - boriel - 2022-03-13

Both are nearly the same. But if you are using a counter variable within the WHILE loop, a FOR / NEXT will be optimal because it will increase the variable for you and this is optimized internally during the traduction to assembler.


RE: WHILE Loop vs FOR/NEXT Loop - RandomiserUsr - 2022-03-25

(2022-03-13, 12:22 PM)boriel Wrote: Both are nearly the same. But if you are using a counter variable within the WHILE loop, a FOR / NEXT will be optimal because it will increase the variable for you and this is optimized internally during the traduction to assembler.

Thanks for that