Download MetaTrader 5

store value in for-loop

To add comments, please log in or register
Traderole
32
Traderole  

Hi guys,

is it possible to store a value inside a for-loop so that I can use this value for further calculations outside the for-loop?

Carl Schreiber
7289
Carl Schreiber  
Hello fellow, yes of course it is possible!
Traderole
32
Traderole  
Carl Schreiber:
Hello fellow, yes of course it is possible!


Haha I should have given an example. Let's assume this:

for(int i = 0,i <= 3; i++)
{
if(i == 2)
	a = i;
	// ---> store a
}
// then further calculations with a

So, how can I store a? I kinda struggle with that task..

Marco vd Heijden
Moderator
5493
Marco vd Heijden  
int a=0;

for(int i = 0,i <= 3; i++)
{
if(i == 2)
        a = i;// ---> store a
        
}
// then further calculations with a

Alert(IntegerToString(a));
Traderole
32
Traderole  
Marco vd Heijden:

Well done. That works perfectly. Many thanks

To add comments, please log in or register