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.

Author
Message
buddzo
16
Years of Service
User Offline
Joined: 27th Jun 2010
Location:
Posted: 27th Jun 2010 18:31
im new to the language and this forum.i cant find anything in DB command set about FOR...ENDFOR loop. But its in the book. is there such a command? If so how is it used?
Sepnon
16
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 27th Jun 2010 19:29 Edited at: 27th Jun 2010 19:29
actually its for..next

=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 27th Jun 2010 19:43 Edited at: 27th Jun 2010 19:43
Here is what Dark Basic Pro Help (The F1 button) says about the "For" command.

Quote: "
FOR
This command will define a program loop that will loop a finite number of times.

Syntax

FOR Variable=Start-Value TO End-Value STEP Step-Value

Parameters

start-Value TO End-Value STEP Step-Value

Value
Enter the appropriate value here.

Returns

This command does not return a value.

Description

The FOR command requires a variable and two values to begin the loop. The variable stores the first value, and is incremented each loop until it reaches the second value. The size of the increment is determined by the STEP value. The NEXT command is placed to mark the end of the loop. As the variable increments during the loop, you can use its value in many ways. Optionally, you can count in descending order by specifying a high first number, a low second number and a negative step value.

Example Code

FOR T=1 TO 10
PRINT T
NEXT T
WAIT KEY


"


Hope that helps, and remember F1 is your friend...

Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 27th Jun 2010 19:43
Unlike other looping commands the For...Next loop provides predictable results. With this loop you can define how many time you want the loop to run. This definitely prevents infinite loops. The starting point for the loop is the FOR statement; the ending point is the NEXT statement as shown in the code snippet provided by Sepnon.

Th FOR command initiates the first loop by making the variable equal to the starting number. When DB reaches the NEXT command, it returns to the FOR command and adds one to the variable. When the variable reaches the ending value, the NEXT statement does not loop back around again. Instead, it ends the loop and continues to the line following.

Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 27th Jun 2010 19:44 Edited at: 27th Jun 2010 19:52
=Prof= you posted while I was writing. Oh well, he has two different angles of it.

Very often the use of a FOR ... NEXT loop allows you to compare information in an array or file. Once you find what you want, you probably don't want to continue the loop. That is easily taken care of by the EXIT command. Within the loop you will probably have something like this:


Login to post a reply

Server time is: 2026-07-25 08:29:26
Your offset time is: 2026-07-25 08:29:26