Insider 3000 :  Features  |  Forum  |  Help on Line  |  FAQ  |  Download  
Home  |   Trading Systems and Indicators  |   Upcoming release news  |   News
Order Insider 3000   |   Resellers - Agents
English    English    Italiano
    Open security
Workgroups
Data file Explorer
Layout
    Windows
Inner Windows
Tooltips
AutoRefresh
Print Chart
    Zoom
Zoom
    Control Panel
Introduction
Charts Properties
Windows Properties
Grids properties
Indicators Properties
Studies Properties
Trading Systems Properties
    Indicators and Studies
Adding an indicator
Modifying an Indicator
Transfer indicator between windows
Deleting an indicator
Adding Studies
Modifying an object
Deleting, coping, cutting, pasting an Object
Indicators Lists
    Data files Management
Introduction
Creating, deleting and modifying Archives
File Format
Historical DDE
Web Server
Archives Update
Edit periods
Deleting periods range
Copy Data to Clipboard
Text file import Wizard
Export data on text file Wizard
Rollover Wizard
Scheduled export on text file
    Analysis
User Indicators Management
Trading Systems Management
Explorers management
Real time alerts windows
Graphical alerts
Pivots Explorer
Candlestick Rules
Candlestick forecaster
Candlesticks signals on chart
Trading systems signals on chart
Statistics
Export - Import source code
    Real time data providers
Providers
    Find Window
Find Window
    Programming language
Introduction
Operators
Data types
Functions
Function, EndFunction
Return
Variables declaration: Dim
Comments
Warnings
The MAIN function
If, Then ... Else
Goto ... label
For ... Next
Do Until ... Loop
Select ... Case
Array
Error Handling
Module variables
Costants
Include (including secondary modules)
Properties
Option (trading systems options)
PRICE keyword (for trading systems)
DATABASE keyword
Special Functions (they change their output depending on the context)
System functions available in the programming language
Indicators Functions
Data Functions
Math Functions
Analysis tools Functions
Date Functions
Boolean Functions
String Functions
Other Functions
Programming Language Editor
    Send Email
Send Mail - Mailer
    Real Time - DDE
Introduction
Subscriptions
Data receiving
    Real Time - Web Server
Introduction
Web Server configuration
Subscriptions
Data receiving
    Real Time - Txt
Introduction
Text file configuration
Subscriptions
Data receiving
    Mailer
Introduction
Mailer Configuration
Emails list
For ... Next

This is one of the most common loops used in programs. It allows to execute a block of instructions between the keyword For and Next a specified number of time.

The syntax is the following:

For counter = Val1 To Val2 Step Inc
    "Block of instructions to execute"
Next counter

"Counter" is a variable which can be used inside the loop itself. "val1" is the starting value which is assumed by Counter, "val2" is the maximum value that can be reach by counter. "Inc" is the incremental step for counter.

Initially "counter" assume the same value as "val1", and every time the loop is executed "counter" is incremented or decremented according with "Inc" until the value "val2" will be reached.

Let's see and example:

For counter = 0 To 10 Step 2

Counter will have value of 0 first, then 2, 4,6,8 and eventually 10.

It is not mandatory to specify the instruction Step and the increment. If they are not specified, the default increment is set to one.

For counter = 0 To 10

Counter will have value of 0 first, and then incremented by a unity, therefore assuming values of 1, 2,3,4 etc, until it reaches the value of 10.

Usually Step is mandatory only to the reverse cycle where counter start from a high value and reaches a lower value, decrementing its value specified by "Inc". The value of "Inc" in this case is negative.

Let's see and example:

For counter = 10 To 0 Step -1

Counter will have value of 10 first, and then decremented by a unity, therefore assuming values of 9, 8,7,6 etc, until it reaches the value of 0.

If the keyword Step is omitted, the default increment is 1, and the interpreter will never execute the loop For assuming that the counter has already reach it final value. Because the keyword Step is optional, the interpreter will not give any error for "reverse loop". This is why a special care should be given when writing reverse loops. To check exactly how a loop will be executed, it is very convenient to use the Editor feature to execute the code line by line.

It is also possible to terminate the For loop before the final condition will be met. This can be particularly useful when seeking a specific value among many others. Once the value has been found, it will be just a waste of time to continue with the rest of the loop.

An early exit can be done using the command Goto Label, where the Label will be positioned after the Next keyword in a For loop.

Let's see and example:


...
...
Count = 0
For Index = 0 To 10
    If (Index^2 = 9) Then
        Goto ExitForLoop
    EndIf
     = Count + 1
Next Index

ExitForLoop:

    ...
    ...
    ...

In this example the variable "Count", keeps track of the number of time the For loops is executed. The exit condition will be reached when Index at the power of 2 is equal to 9, i.e. when Index = 3. When exiting from the loop, Count = 2 because the line where is incremented is executed only twice.

Inside For or Do Until loops, there can be also other nested loops.


...
...
For IndexA = 0 To 10
    For IndexB = 5 To 20
         For IndexC = 0 To 3
         Next IndexC
    Next IndexB
Next IndexA
...
...

Special care should be taken to make sure that every loop has a different index variable, and every loop is entirely contained into another.

Contact us    Collaboration
TraderSoft s.r.l. 2003-2010 - P.Iva 03808860286 - Copyright