Here’s a practical example of a while loop. Run this in Zorro:
function main()
{
var n = 0;
while(n < 10) {
n = n + 1;
printf("%.f ",n);
}
}
This little program adds [B]1 [/B]to the variable [B]n[/B], prints the variable to the message window, and repeats this until [B]n [/B]is [B]10[/B].
Loops are very useful when something has to be done repeatedly. For instance, when we want to execute the same trade algorithm several times, each time with a different asset. This way we can create a strategy that trades with a portfolio of assets.
We are now at the end of the first part of the course. In the next part we’ll begin with developing real trading strategies; you’ve already learned all programming stuff that you’ll need for those lessons. But there’s far more to programming - we haven’t touched yet concepts such as macros, pointers, arrays, or the Windows API. lite-C also supports some elements from C++, the ‘big brother’ of C - such as classes or function overloading. If you want, you can continue on your own with online C tutorials. You can also visit the Gamestudio community that uses Zorro’s lite-C language for programming small or large computer games.
If you want to look at some ‘real’ C program, run the script [B]Mandelbrot[/B]. It has nothing to do with trading and you will probably not understand yet much of the code inside. It is a normal Windows graphics program. Don’t worry, trading strategies won’t be this complicated - it just shows that programming has a lot more depth and can be a lot more fun even without earning money with it.