Errors, bugs, questions - page 326

 
Urain:

In the first post you are doing assignment operations, multiple cascading assignment is acceptable. Here you are trying to do a multiple comparison.


I know how to compare, but if(a<b<c) it works and looks prettier although the help doesn't say anything about it. how does it work faster?
 
sergey1294:
I know how to compare, but if(a<b<c) it works and looks prettier, although the help doesn't say anything about it. But how does it work faster?

Your expression is equal to this one

if(a<(b<c))
you compare b and c, the result of this comparison will be 0 or 1 and then you compare this result with a.
 
sergey1294:
I know how to compare, but if(a<b<c) it works and looks prettier, even though the help doesn't say anything about it. How does it work faster?

This is how it works.

if(a&&b&&c==3)Alert("a=b=c=3");
if(a<b&&b<c)Alert("a<b<c");
  if(a==b)Alert("a=b");

and this doesn't.

 if(a<b<c)Alert("a<b<c");
 if(a=b=c=3)Alert("a=b=c=3");
 if(a==b==c==3)Alert("a=b=c=3");
 if(a==b==c)Alert("a=b=c"); //Вот нежелание работать этого примера для меня странно (хотя может так и задумано)
Urain:

Your expression equals this

you compare b and c, the result of this comparison will be 0 or 1 after which you compare this result with a.
With this logic everything becomes clear, but for some reason I think a and b will be compared first (may be I'm wrong of course)...
 
Urain:

Your expression is the same as this one.

you compare b and c, the result of this comparison is 0 or 1 and then you compare this result with a.

I see, but here's the trick with this expression, but it doesn't work

void OnStart()
  {
//---
   int a=1;
   int b=2;
   int c=3;
   int d=3;
//---   
   if(a!=b<c==d)Alert("");
   else Alert("Условие не верно");
//---
  }
 
Interesting:
... Only I somehow think that a and b will be compared first (I may be wrong of course)...
Yes, I'm just mechanically wrong, first there's a left-hand comparison then a right-hand one.
 
sergey1294:

I see, but here's the trick with this expression, but it doesn't work

No, it's just that you have to take into account the priorities of the operations and the comment from Urain.

There is no problem with this expression too, but it glitches very badly.

if(a<b<c)Alert("a<b<c");

This issue is described in detail in the edit, section "Priorities and order of operations". (Priority and order of operations must be taken into account).

So if I understand correctly, the comparison according to the compiler looks like this (taking into account comments from Nikolay)

if((a!=(b<c))==d)Alert("")
 
Interesting:
What is the approximate size of the list? Maybe there is a limit to the size of the list...
Exactly 100 lines.
 
-Alexey-:
Exactly 100 lines.

Experimented with one of my libraries (110 functions), displayed 100 to 106 in the list (and a different number all the time, but not 110).

 

When reading the .csv file, several problems arose at once. In order to try to figure out the reasons for the malfunction, I wrote a simple script. The script reads data from the file "test.csv". As soon as it gets to the end of the file it prints the iteration number of the "for" loop, the file size and the file pointer position into the log. But incomprehensible things happen here, namely: The file "test.csv" has only 15 lines, so the number of iteration of the loop "for" must be 14, but the journal generates 0. The file size is printed correctly, but the file end pointer position has a size bigger than the file itself for some reason. Script code:

void OnStart()
  {
   int handle;
   ulong i, size;
   double _Ask, _Bid;
   string str;
      
   handle = FileOpen("test.csv",FILE_CSV|FILE_READ,',');
   
   if (handle != INVALID_HANDLE)
     {
      size = FileSize(handle);
      
      for (i = 0; i < size; i++)
        {
         str = FileReadString(handle);
         _Ask = FileReadNumber(handle);
         _Bid = FileReadNumber(handle);
        
         if (FileIsEnding(handle))
           {
            Print(i," ",size," ",FileTell(handle));
            break;
           }
        }
     }   
      
   FileClose(handle);

   return;
  }

"test.csv" file and log attached. Who has any thoughts on this question?

P.S. The most interesting thing is that in MT4 this script works without errors.

Files:
test.zip  1 kb
 
DenisR:

When reading the .csv file, several problems arose at once. In order to try to figure out the reasons for the malfunction, I wrote a simple script. The script reads data from the file "test.csv". As soon as it gets to the end of the file it prints the iteration number of the "for" loop, the file size and the file pointer position into the log. But incomprehensible things happen here, namely: The file "test.csv" has only 15 lines, so the number of iteration of the loop "for" must be 14, but the journal generates 0. The file size is printed correctly, but the file end pointer position has a size bigger than the file itself for some reason. Script code:

"test.csv" file and log attached. Who has any thoughts on this question?

P.S. The most interesting thing is that in MT4 this script works without errors.

At a glance, the whole file is written to str...
Add FILE_ANSI flag, as it reads unicode by default:)
Also, i will be 15, as there is a blank line at the end.
Reason: