Forum
WHILE Loop vs FOR/NEXT Loop - Printable Version

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



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

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 - 03-13-2022

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 - 03-25-2022

(03-13-2022, 11:22 AM)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