Loop over variables (index)

 

Hi,

Can we append the prefix of a variable with an index: variable_name (index) in the aim of creating a loop over the index.

variable_name_1

variable_name_2

.

.

.

variable_name_N


for(int s=1; s<=SYMBOLS_COUNT; s++)
     {   
    ArrayResize(InputVector_Clos_P_(s),histo); /* How ? */

//ArrayResize(InputVector_Clos_P_1,histo); 
//ArrayResize(InputVector_Clos_P_2,histo); 
//ArrayResize(InputVector_Clos_P_3,histo); 
       
     } 

  Is there any operator as "&" in VBA por example? 

Thanks  

 

It's not possible to change a variable name dynamically (in VBA neither anyway). You need to use an array.

What are you trying to achieve ?

 
From your code I can guess you are trying to loop into a list of symbols available to trade with the platform , and use it for multi trading currency.
 
Why not to use an array variable_name[]?
 

Thank you guys for your responses.

The goal is simply to use variables in a loop and this by intervening only on the number of variables. 

@Alain : in VBA, i mean to use the variable like in the example 

For I = 1 To 2
    MsgBox ("y" & I)
Next I


 The aim is not to create variable but only use it, like in first example , i want to  resize those three vectors only 

@Stanislav: How we can apply array variable_name[] for the example below ? thanks in advance 

for(int s=1; s<=3; s++)
     {  
    ArrayResize(InputVector_Clos_P_(s),histo);

//ArrayResize(InputVector_Clos_P_1,histo);
//ArrayResize(InputVector_Clos_P_2,histo);
//ArrayResize(InputVector_Clos_P_3,histo);
      
     }
 
You may have a look at this article, specifically at the clause "Creating Multidimensional Arrays Using OOP". This is just one of possible solutions. Using operator[] overload you may mimic multidimentional arrays almost fully.
Reason: