2 Loops into each other

 

Morning,

i want to use a loop with different 2 variables. How does this work?

for (int j; j >= 1 ; j--) && (int i; i >=1 ; i)
    {
    Formula[j,i] = (3*j+i*2)
    }
 

you probably mean something like 

for (int j=?; j >= 1 ; j--)
   for(int i=?; i >=1 ; i--)
    {
    Formula[j][i] = (3*j+i*2);
    }

 Note that if you did intend to assign values to an array that array indexes start at 0, whereas your loops only count down to 1

 
GumRai:

you probably mean something like 

 Note that if you did intend to assign values to an array that array indexes start at 0, whereas your loops only count down to 1

With Formula[j] [i]   i get the error '[' Wrong dimension.
 
Fx90:
With Formula[j] [i]   i get the error '[' Wrong dimension.
Please show your code.
 
Read/know the Book - you would have found this!
 
//+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

//buffers
double Formula[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

    for (int j=20; j >= 1 ; j--)
    for(int i=20; i >=1 ; i--)
    {
    Formula[j][i] = (3*j+i*2);
    }
    Comment(""+Formula[2][3]+"");
  }
  
  
//+------------------------------------------------------------------+

Error: '[' wrong dimension.

Which Part do you mean in the Book? I see there no loop with 2 variables in this way?

 
double Formula[];

    Formula[j][i] = (3*j+i*2);
  1. Array has one dimension. Assignment has two dimensions. Do you think that might be a problem?
  2. Array has no size. Assignment will fail with array dimension exceeded error.
 

What do you ask me that?

Its not my code, GumRai posted it and angevoyer wrote  that i should post the code..


i tried it this way and it doesnt worked..


Please dont post any more answers in my topic if you have no solution. I dont want all these kind of "spam" that i get here. Since i am here i havent got any real good answer..


if theres someone in the forum who really has intelligence and skills, please post a code example. I think it isnt a very long code..

 
Fx90:

Error: '[' wrong dimension.

Which Part do you mean in the Book? I see there no loop with 2 variables in this way?

2) In the book you could have read about a correct for-loop and how it works:

for(i=Nom_1; i<=Nom_2; i++) {       // Cycle operator header
  ...

How can for(..) be an boolean value (your code):

for (int j; j >= 1 ; j--) && (int i; i >=1 ; i)


2) In the book you could have further found - if you would have been willing to - the 2-dim arrays (very well explained, even for beginners!) and 'nested' loops there:

   for (int i = 20; i<=90; i=i+10)              // Cycle for tens
     {
      for (int j=1; j<=9; j++)                  // Cycle for units
         Text[i+j] = Text[i] + Text[j];         // Calculating value   
     }

I feel (may be others here too) a bit ripped off by people answering questions that they can find out themselves if they only would make a little effort to learn the basics: read the book, study the code of others, ...

It's my understanding this forum is not an elementary school for mt4.

 

thx, i will do that. If its elementary, why nobody has all the day a answer & code for it?  90% of the people in this forum have to be in the elementary school..

it would all be quicker if you had posted the code at 12pm.. 


But sorry if my questions are too stupid for your grandeur..

i just come from the country where the people usually still till there fields, milk the cows and dont programm..


nice weekend
 

I feel (may be others here too) a bit ripped off by people answering questions that they can find out themselves if they only would make a little effort to learn the basics: read the book, study the code of others, ..





I could not agree more
Reason: