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.

DarkBASIC Professional Discussion / Alternatives to the loop command

Author
Message
midniteferret
15
Years of Service
User Offline
Joined: 14th Oct 2010
Location: where ever you are not
Posted: 15th Oct 2010 23:25
Is there another command that can loop commands between two point continuously besides the do and loop command? Thanks!
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 16th Oct 2010 14:28
There's a bunch of them,


Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 16th Oct 2010 16:56
Each of them have their usefulness, if theres a specific situation you need an alternative for, we're always happy to help.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Oct 2010 18:05
Try to avoid using "goto" though (it's considered bad practice), if you want to know why try typing "goto" in the search at the bottom of the page. There are probably hundreds of posts giving arguments against using it... in fact here's a page in wikipedia about it:
http://en.wikipedia.org/wiki/Goto

...if you're interested that is!

midniteferret
15
Years of Service
User Offline
Joined: 14th Oct 2010
Location: where ever you are not
Posted: 16th Oct 2010 21:38
Thanks, but what is does the while/ end while command do?

-Sharpie, not even once...
Eminent
16
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 16th Oct 2010 23:37
Label:\ Goto Label:
Didnt know about that one.


TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Oct 2010 23:58
while (whatever you want to check)=true

--do stuff

endwhile

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 17th Oct 2010 00:24
FOR/NEXTs loop for specific ranges like 1 to 10. If you add STEP at the end you can skip numbers in the range or even go backwards from 10 to 1 with STEP -1.

WHILE/ENDWHILEs are useful if you don't always want whats inside the loop to be ran because the condition is checked first before entering the loop.

REPEAT/UNTILs conditional check is at the end so it'll always run what's inside the loop at least once before the check to leave the loop.

All loops can leave in the middle of the loop with the EXIT command (going to the line under the close of the loop).


@ Eminent:

It's like GOSUB but without the ability to RETURN... which is why we don't like to use GOTO at all. If you haven't used it you should at least use it once just to see what it does. You were right to keep away from it and only use GOSUB and functions.

Login to post a reply

Server time is: 2026-07-24 23:12:33
Your offset time is: 2026-07-24 23:12:33