what does it do? (Idiot question)

Post Reply
User avatar
ironrick
Trader
Posts: 85
Joined: Wed Nov 16, 2011 7:04 pm
Location: North Idaho Boy, USA

what does it do? (Idiot question)

Post by ironrick »

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
"A problem well put is half solved."
garyfritz

Re: what does it do? (Idiot question)

Post by garyfritz »

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;".
User avatar
ironrick
Trader
Posts: 85
Joined: Wed Nov 16, 2011 7:04 pm
Location: North Idaho Boy, USA

Re: what does it do? (Idiot question)

Post by ironrick »

Thanks! just what I needed!

R
"A problem well put is half solved."
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: what does it do? (Idiot question)

Post by gaheitman »

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
User avatar
ironrick
Trader
Posts: 85
Joined: Wed Nov 16, 2011 7:04 pm
Location: North Idaho Boy, USA

Re: what does it do? (Idiot question)

Post by ironrick »

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
"A problem well put is half solved."
Post Reply

Return to “Coders Hangout”