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 Discussion / Arrays and FOR NEXT

Author
Message
Soroki
19
Years of Service
User Offline
Joined: 26th Jan 2006
Location: United States
Posted: 23rd Aug 2006 20:38
If there are two things on DBC I don't understand well, its arrays and FOR NEXT commands. Arrays are confusing. FOR NEXT seems like it has no point. Maybe its just because I don't really get them. Could someone please list why these commands are useful and situations in which they are useful. I would greatly appreciate it.

If we're here to help others, what exactly are the others here for?
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Aug 2006 22:47 Edited at: 23rd Aug 2006 22:47
For/Next Loops:
You might want to make objects 1-4 a size of 34, you could do:

or...



Arrays:
Let's say you wanted 5 variables, and you wanted them to have random numbers, you could do -


or...


Now, try this with the for/next loop:




Both are very simple, and very usefull.

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 24th Aug 2006 00:12 Edited at: 24th Aug 2006 00:16
I made a tutorial on arrays.. I hope it helps. (the link is in this post if you can't find it)

Of course, Zotoaster's example should help too. Mine goes a bit further, but it starts there


FOR/NEXT:

It cycles a variable through numbers, starting at the first number, and ending at the last. Say you had "FOR v = 1 to 6". It will cycle the variable v through the numbers 1 2 3 4 5 and 6. In each cycle, it will do the desired action (i.e. what you put inbetween the FOR and the NEXT.)

Sorry if It sounds like I'm repeating Zotoaster.

Soroki
19
Years of Service
User Offline
Joined: 26th Jan 2006
Location: United States
Posted: 24th Aug 2006 21:05
You guys are officially awesome! That tutorial was very helpful, and now I can use FOR NEXT in my programs without wondering WTF I'm doing. Thanks! I would type thanks 100 times but then I would be spamming, lol.

If we're here to help others, what exactly are the others here for?
Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 25th Aug 2006 02:31
i use arrays and For/Next So damn much .. Mainly as they can save lines, and For/Next is ESPECHIALLY useful for 'unknown' variables

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Aug 2006 17:26
glad to hear it helped

Login to post a reply

Server time is: 2025-05-26 01:07:39
Your offset time is: 2025-05-26 01:07:39