Self-learning the MQL5 language from scratch - page 34

 
Реter Konow:
Look: you set both variables to true beforehand (before the condition). That is, they will ALWAYS be true at every launch of the script. Why, then, do we need a condition? Is it possible in this program that variables explicitly initialized with true may not be true? - No! Because you have written this value into them and it cannot be changed anywhere in the code.

In this case, the condition is not needed, nor are the variables themselves needed, because ALWAYS the result of the script will be the string "I will learn the language".

However, having variable values calculated in additional functions can lead to different combinations of results - one will return true, the other false, or both will return false, or both will return true... In this case, the written condition is justified by possible variations in variable values leading to printing different strings.

Thanks, Peter, for the clarification!

Regards, Vladimir.

 
Valeriy Yastremskiy:

There is no logic, because these are variables defined in the script. They should either be variables that the user sets via an intu or derived from functions, which is even more logical.

I.e. the utility of the script should always be there. Just a script that displays text is useless. And with data entry this script will tell you if you can learn the language) And with functions, they simply do not exist, they are not written, and if you write, for example, a calculation from the level of knowledge of mathematics, knowledge of other languages, how much free time, level of desire and ability to memorize and the function will return True or False based on the calculation, the usefulness will be more))))

Valery, thank you very much for the detailed reply!

Sincerely, Vladimir.

 

Here's a revised version of the script, including hints for those new to the script who may or may not be reading this thread:

//+------------------------------------------------------------------+
//|                                                            1.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
#property script_show_inputs
//---
input bool достаточно_времени=true;
input bool достаточно_терпения=true;
//---
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   if(достаточно_времени && достаточно_терпения)
     {
      Print("Я выучу язык MQL5!");
     }
   else
     {
      Print("Я не выучу язык MQL5!");
     }
  }
//+------------------------------------------------------------------+

Added to the script:

  1. "display properties window before running the script";
  2. Ability to change external variables.

Regards, Vladimir.

 
Реter Konow:
Yes, this variant is correct in terms of syntax, but it still lacks logic. Yesterday Vasily wrote a lot about functions. This is where they are needed:

bool Sufficient_time = Sufficient_time();

bool Sufficient_patience = Sufficient_patience();

if(Sufficient_time && Sufficient_patience)Print("I will learn the language!");

else Print ("I won't.");

You have to calculate time and patience before you put them into a condition instead of setting them by default, because it makes no sense to have the condition - it is always true.

+1. That's correct.

 
Реter Konow:
"... You have to calculate time and patience before you put them in a condition rather than setting them by default, because the meaning of having a condition disappears - it is always true."

I will definitely do that, but later, as my "pot" is already boiling, so I need to cool it down a bit.

Sincerely, Vladimir.

 
MrBrooklin:

Here's a corrected version of the script, taking into account the hints:

Added to the script:

  1. "display properties window before running the script";
  2. Ability to change external variables.

Regards, Vladimir.

Right! And then try to write functions that calculate the values of these variables depending on the values of other external variables.

That is, function Enough_time() will take values of external variables:

input datetime Days_training = 100;
Input uchar Hour_in_day = 5;
... and so on...

In other words, the functions will take the values of your input variables and make calculations, and the result will be returned in the variables Sufficient_time and Sufficient_patience, which, then, you can put into a condition with multiple options, each of which will print a different string.

 
Реter Konow:
You are right! And then try to write functions that calculate the values of these variables depending on the values of other external variables.

That is, Sufficient_time() will take the values of external variables:

input datetime Days_training_day = 100;
Input uchar Hour_in_day = 5;
... and so on...

Then, the functions will take the values of the input variables and make calculations, and the result will return into the variables Enough_time and Enough_patience, which you can then put into a condition with multiple options, each of which will print a different string.

Peter, put your suggestion into my self-study plan. The result will be later posted in the form of code script.

Regards, Vladimir.

 
MrBrooklin:

I will definitely do that, but later, as my "pot" is already boiling, so I need to cool it down a bit.

Sincerely, Vladimir.

Of course, take a break).
 
Реter Konow:
Right! And then try to write functions that calculate the values of these variables depending on the values of other external variables.

That is, Sufficient_time() will take the values of external variables:

input datetime Days_training_day = 100;
Input uchar Hour_in_day = 5;
... and so on...

It's more or less clear with time, but the variables for "Enough Patience" are still a problem. What should I put in them? Have patience or no patience? At least these two parameters? I need to think about it.

Regards, Vladimir.

 
MrBrooklin:

Time is more or less clear, but the variables for "Enough patience" are a problem. What do you put in them? Is there patience or no patience? At least these two parameters? I need to think about it.

Regards, Vladimir.

1. Mood (enumeration of types by initialised conditional units).

2. Self-perception (the same thing).

3. Motivation quotient.

4. The coefficient of belief in forex

...

Come up with a couple of calculation formulas and you're done).