If-else, switch, goto, program flow control, was: Backtest question

Hi!
I have a backtest formula where I like to use the Param-function to control which entry method I would like to use this time.
If I enter "1" in the Param-function, I would like to go to a specifc part of the code, and if I enter "2", to another part.

Is there a way to jump to a specific part of the code using AFL?

Best regards,
Leif Axelsson
Sweden

Hi,

Some decades ago when i was related to programming in those "old" languages and also a little bit of C that i remember, there was a Goto statement which use to jump code.

But it was considered a bad programming practice and often discouraged. sometimes you may set something and just jump over good code and make the program worse.
Maybe that is why even language like AFL may not implement it like many newer languages.

The best way is to use if-else sections or write code in functions and call specific function or pass parameter to single function and achieve multiple code scenarios.

My answer may not be the solution but when i saw the word jump to code, i had flashback of my old days.

Mr Tomasz would be able to give good comments on this.

Gotos are bad and old (so '70) and are not needed when you have structural programming statements like switch
http://www.amibroker.com/guide/keyword/switch.html

Because '70-style "goto" promotes bad programming style it is NOT supported in AFL. Use if-else, switch, functions and other good style flow control statements.

If you have separate parts, why not add some CLEAN design by putting separate parts into functions

function OneThing()
{

}

function TheOtherThing()
{

}

input = Param("whatever", 1, 1, 2, 1 );

if( input == 1 ) 
 OneThing();
else 
  TheOtherThing()

or using switch

function OneThing()
{

}

function TheOtherThing()
{

}

input = Param("whatever", 1, 1, 2, 1 );

switch ( input )
{
 case 1: 
 OneThing();
 break;

case 2:
  TheOtherThing();
  break;

default:
  break;
}

BTW: your question was not "backtest question". Choose your subject wisely so others can find messages later by their true nature. I changed subject to better reflect the content.

3 Likes

nice reply :slight_smile:

just as i thought but i haven't programmed for very long.
AB has refreshed a lot of memories.

Hi!

ThankYou for all help!

/Leif