stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

what does it do? (Idiot question)
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=280
Page 1 of 1
Author:  ironrick [ Sat Jan 21, 2012 1:44 am ]
Post subject:  what does it do? (Idiot question)

I am teaching myself mql by looking through code examples from this forum and looking up the bits I don't understand. Wish me luck.

Question: in the following code example,

Code: Select all

//--------------------------------------------------------------------
// countticks.mq4
// The code should be used for educational purpose only.
//--------------------------------------------------------------------
int Tick;                              // Global variable
//--------------------------------------------------------------------
int start()                            // Special function start()
  {
   Tick++;                             // Tick counter
   Comment("Received: tick No ",Tick); // Alert that contains number
   return;                             // start() exit operator
  }
//--------------------------------------------------------------------
What does the "++" mean/do? I have also seen "--"? I have googled but to no avail.

I now it seems a really small thing but I can't figure out what is being represented by ++. I know what the code sample does as a whole but...

Does it simply mean increment by 1?

Thanks in advance!
Rick
Author:  garyfritz [ Sat Jan 21, 2012 2:17 am ]
Post subject:  Re: what does it do? (Idiot question)

That originally came from C, back in the early 70's. I'll spare you the history of why they thought that was necessary in a "high-level" language, but anyway, it is an incrementor. In C and C++, but apparently NOT in MQL, you can use it before OR after a variable. When used before a variable, it increments the value and returns the incremented value. When used after, it returns the value and then increments it.

For example, fake code:

Code: Select all

i = 0;
print i;     // prints 0
print i++;   // prints 0
print i;     // prints 1
print ++i;   // prints 2, but does NOT work in MQL
print i;     // prints 2
Trivia: that's where C++ got its name -- it was C, with stuff added on. "C incremented." Har har, geek humor. :D

-- does the same thing, except obviously it decrements instead of incrementing.

So "var++;" is exactly equivalent to saying "var = var + 1;".
Author:  ironrick [ Sat Jan 21, 2012 2:45 am ]
Post subject:  Re: what does it do? (Idiot question)

Thanks! just what I needed!

R
Author:  gaheitman [ Sat Jan 21, 2012 2:16 pm ]
Post subject:  Re: what does it do? (Idiot question)

ironrick wrote:Thanks! just what I needed!

R

Relevant articles:

http://docs.mql4.com/basis/operations/math

and

http://docs.mql4.com/basis/operations/assign

Funny, the URL should be "basics" not "basis".

George
Author:  ironrick [ Mon Jan 23, 2012 5:56 am ]
Post subject:  Re: what does it do? (Idiot question)

gaheitman wrote:
ironrick wrote:Thanks! just what I needed!

R

Relevant articles:

http://docs.mql4.com/basis/operations/math

and

http://docs.mql4.com/basis/operations/assign

Funny, the URL should be "basics" not "basis".

George

Awesome George!

Thanks very much!

BTW, it is your MillerScore indi that I am trying to understand so that I can keep the work going there. Thanks for all you do! :)

R
All times are UTC Page 1 of 1