3. Variables and Treir Types

Bookmark and Share

This time, let’s go over the basic knowledge of programming we need for Meta Editor. As a tutorial, practice is the base of this site. But this is a preparation before that step.

This is going to be a abstract explanation of programming so if you have experienced programming with other kinds of language, you can skip this part.

0. Typical Things about Programming

These are things you must know about programming:

  • Put a “;” (semi-colon) at the end of each sentence (order).
  • When using a string in the program, enclose it with a " (double-quotation mark) or ' (single-quotation mark).

These are the least things you should remember. I’m sure you’ll get used to this as we go on.

1. What is a Variable?

Have you ever heard of the word “variable”?

I think you have heard it in your mathematic lectures. Mathematically it means “a number that is unknown or that can’t be defined as a unique number”. 
For example, in “x2+2x+1=0” x is used as a variable. (x=-1 is supposed to be unknown in the sentence.)

The “variable” we use in programming is a little different from this. It’s something like a label to call up an arbitrary data.

For those who have some experience with programming the concept would probably be familiar. But for those who have not, this is a little complicated idea. So let’s take a look at some examples.

  1. int x = 0; // "x" will be set to 0 by this.
  2. x = x + 1; // "x+1" (which means 0+1=1) will be set as "x" by this.
  3. Print(x); // the value of "x" will be printed by this.

In the example above, we labeled ”0” as “variable x”. Thus, "x=0" means “define x as 0”. I will explain about “int” next.

Let’s think about another example.

  1. string message = 'Hello, ';
  2. message = message . 'world!';
  3. Print(message); // "Hello, world!" will be displayed

In this way, you can label letters by variables and control letters.

2. Data Types

Variables can indicate numbers and letters. However you need to clearly specify what kind of data is contained.

This is a big difference from Script series language such as PHP so those who have experience in programming should be careful, too.

There are many kinds of data types. These are the ones you should at least know.

  • Integer
    Just as written it is integers. Enter “int” in front of the variable.
  • Floating Point
    This is numbers that include decimals. Enter “double” in front of the variable.
  • Date
    It expresses Unix Time, the seconds passed since (1/1/1970). Enter “date” in front of the variable. 
  • String
    It indicates Strings. You can contain both 1 byte letters and 2 byte letters. Enter “string” in front of the variable. 
These are the examples.
  1. int example1 = 12;
  2. double example2 = 3.1415;
  3. date example3 = 1214850744;
  4. string example4 = 'Types of variables are defined like these.';

When you make a program by using Meta Trader be careful not to forget to define the types of variables.

up