Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / do loops or repeat until?

Author
Message
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 2nd Aug 2023 17:11
a do loop compared to a repeat until? wha is the dif besides of course the until condition? is there any effect on performance, memory ect? im asking because i do have a lot of do loops but i started using repeat until in some cases and i like repeat until better for some reason
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 3rd Aug 2023 20:19
Looking at the byte code:

compiles to


While

compiles to

Instruction 5 jumps the IF block when the condition fails. Instruction 6 performs the loop exit. Instruction 7 repeats the loop. So an extra JUMP instruction is needed for do.loop.

However, it really depends on what you need the code to do.
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 4th Aug 2023 03:48
well say for a my game menu where the until condition is when the "back" button is pushed, it will exit that menu as apposed to the do loop with the exit command instead when the "back" button is pushed
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 6th Aug 2023 23:41
It makes no difference at all in a menu.
It won't make any difference in 99% of all loops, unless for some reason you want to count to 100 million, which on my system takes .5 seconds longer using the do..loop ( adambiser already explained the reason ).
Other calculations inside the loop will burn significantly more cpu time than the loop itself, so the looping method is imho negligible.


PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-05-02 15:28:38
Your offset time is: 2024-05-02 15:28:38