Questions from Beginners MQL4 MT4 MetaTrader 4 - page 241

 

Hello programmers !

How to solve the comparison of two numbers in a for loop ?

What would it take to find A==B without the case of the loop i ?

In the loop compare two numbers is only on i, for example it compares them if i == 1 , then it only goes through the numbers A and B with the number that are equal to i .

I want it to try all of the given numbers with each other without the case of the cycle i. How to implement this in code, if you can show a code example.

Thank you.

а

#property copyright "."
#property link      ""
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
 
    for(int i=1; i<10; i++)
     {   
      double x=1.0;
      double y=0.5;
        
      double A = x*i;
      double B = y*i;
  
      Alert(" i = ",i,"     A = ",DoubleToStr(A,1),"     B = ",DoubleToStr(B,1));
      
      //КАК НАЙТИ СРАВНЕНИЕ ЧИСЕЛ А == В БЕЗ УЧЕТА i ?
   }
  }
//+------------------------------------------------------------------+
Files:
Test_1.mq4  2 kb
 

Make a loop in the loop. First compare the first A with each of the ten B's, then the second A, etc.

 
Aleksei Stepanenko:

Do a cycle in a loop. First compare the first A with each of the ten B's, then the second A, etc.

Thank you for your answer.

9 times? in this cycle 9 A, and 9 B .

I have a cycle of 100 A's and 100 B's and that's already going over each A and B.... 100 times. It's a nightmare.

There's no other way?

 

It all depends on the task at hand. It may be that you don't need to search for anything at all. For example, if some values are stored in an array beforehand.

What is required is not clear from your example so far. What are these comparisons for, what do you want to get?

 
Aleksei Stepanenko:
It all depends on the task at hand. Maybe you don't need to search for anything at all. For example, if some values are stored in an array beforehand.

I have thought about it only with arrays I have a problem too old to understand them. But if an example was shown maybe I could figure out how to apply it. I thought about a two-dimensional array, but never got around to implementing it. The data is output the same in one-dimensional array as in loop....

I was thinking maybe someone has come across this and have a solution they could share.

 
Aleksei Stepanenko:

It is still not clear from your example what is required. What are these comparisons for, what do you want to get?

I put the comparison data into the function of the arrow object, it only sees those comparisons that match the i, which is what I described above.
 

In order to suggest something, you need to describe the problem. Not the solution, how you see it, but what you want to get out of it. Then you can think about the implementation.

 
Aleksei Stepanenko:

In order to suggest something, you need to describe the problem. Not the solution, how you see it, but what you want to get out of it. Then we can think about the implementation.

Thank you, Aleksei, I will take your first advice, I have already implemented it. I just wanted to reduce the code, it was too much. I thought there was a simple solution, in private I have already been told that there is no other way.

 
Aleksei Stepanenko:

In order to suggest something, you need to describe the problem. Not the solution, how you see it, but what you want to get out of it. Then we can think about the implementation.

I've been thinking, is it possible to do this by storing double data in the array? As far as I know, you can only put int into an array?

I think you could do something with this.......

А[100]={0,1,2,......99};
 

In programming, there is rarely only one solution possible. There are always options. You don't say anything about meaning, so I don't know what to say.

An array can contain data of different types:

int a[];
double b[];
string c[];
char d[];
Reason: