Self-learning the MQL5 language from scratch - page 32

 
#property script_show_inputs
input string inA = "достаточно времени";
input string inB = "достаточно терпения";
const string a = "достаточно времени";
const string b = "достаточно терпения";

//+------------------------------------------------------------------+
void OnStart()
{
   if(inA == a && inB == b)
   {
      Print("я выучу язык MQL 5");
   }
}
//+------------------------------------------------------------------+

UPD:

I don't like strings, luckily MQL allows explanations of input variables and sets to be created as a comment, it's better that way:

#property script_show_inputs
enum E_STATE
{
   STATE_A/*достаточно времени*/,
   STATE_B/*НЕ достаточно времени*/,
   STATE_C/*достаточно терпения*/,
   STATE_D/*НЕ достаточно терпения*/,
   STATE_E/*достаточно денег*/,
   STATE_F/*НЕ достаточно денег*/
};
input E_STATE inA = STATE_A;
input E_STATE inB = STATE_C;

//+------------------------------------------------------------------+
void OnStart()
{
   if(inA == STATE_A && inB == STATE_C)
   {
      Print("я выучу язык MQL 5");
   }
   else
   {
      Print("я НЕ выучу язык MQL 5");
   }
}
//+------------------------------------------------------------------+
 
Igor Makanu:

UPD:

don't like strings, good thing MQL allows explanations of input variables and sets to be created as a comment, better that way:

Cool! With such a simple task, so many different solutions! Thank you.

Regards, Vladimir.

 
MrBrooklin:

Great! With such a simple task, so many different solutions! Thank you.

Sincerely, Vladimir.

Now it would be more correct to follow logic rather than practice syntax. Logic suggests that the result of the question "will or will not learn the language" can only return a function that calculates some parameters associated with this. Since the function must return yes/no result, it is declared with type bool. You can call the function directly from the if() condition.

if(Enough_time() && Enough_patience()) Print("I will learn the language!");

else Print("I won't learn the language...");


Now, think about the content of the functions.

 
Реter Konow:
Alas, this is a misleading, leading you down an unknown road of learning. What does "state" and this enumeration have to do with it? It's a fiction on a level playing field.

Now it would be more correct to follow logic rather than practise syntax. Logic suggests that the result of the question "will or will not learn the language" can only be returned by a function that calculates some parameters related to it. Since the function must return yes/no result, it is declared with type bool. The function can be called directly from the if() condition.

if(Enough_time() && Enough_patience()) Print("I will learn the language!");

else Print("Alas, I won't learn the language...");


Now, think about the content of the functions.

You're picking on me, of course the comment is incomplete there, the first variableinA is as it should be, a condition of execution so to speak, and the seconda, is as it is in fact)))))))))) And that's why inA is entered via an instance, and is immutable, and the variable a .... although yes, it shouldn't be a constant variable, but a static or just a text type))))

But it still makes sense)

 
MrBrooklin:

Great! With such a simple task, so many different solutions! Thank you.

Regards, Vladimir.

And there are more patterns...

#property script_show_inputs

enum EStateTime
{
   TimeOk=0/*достаточно времени*/,
   TimeFail/*НЕ достаточно времени*/
};
enum EStatePatience{
   PatienceOk=0/*достаточно терпения*/,
   PatienceFail/*НЕ достаточно терпения*/
};
enum EStateMoney{
   MoneyOk=0/*достаточно денег*/,
   MoneyFail/*НЕ достаточно денег*/
};
input EStateTime time = TimeOk;
input EStatePatience patience = PatienceOk;
input EStateMoney money = MoneyFail;

//+------------------------------------------------------------------+
void OnStart()
{
   if(Check(time) && Check(patience))
   {
      Print("я выучу язык MQL 5",(Check(money)?NULL:" и это не зависит от денег"));
   }
   else
   {
      Print("я НЕ выучу язык MQL 5");
   }
}
//---------------------------------------------------------------------
template<typename T>
bool Check(T condition){
   return condition==0;
}

Yep, there is a ternary operator, too.)

From this path (understanding and knowing how to write it) starts, in fact, the developer's way. IMHO

Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
  • www.mql5.com
В качестве первого операнда – "выражение1" – может быть использовано любое выражение, результатом которого является значение типа bool. Если результат равен , то выполняется третий операнд – "выражениеЗ". Второй и третий операнды, то есть "выражение2" и "выражениеЗ", должны возвращать значения одного типа и не должны иметь тип void. Результатом...
 
Реter Konow:
Alas, this is a wrong way of learning which leads you nowhere. What has "state" and this enumeration got to do with it? It is a fiction on a level playing field.

Now it would be more correct to follow logic rather than practise syntax. Logic suggests that the result of the question "will or will not learn the language" can only be returned by a function that calculates some parameters related to it. Since the function must return yes/no result, it is declared with type bool. You can call the function directly from the if() condition.

if(Enough_time() && Enough_patience()) Print("I will learn the language!");

else Print("I won't learn the language...");


Now, think about the content of the functions.

Hello, Peter! I certainly will! It's just that the question was asked:

"...The control question: 'enough time' - what type can this variable be without a compiler warning...".

That's what I was trying to answer. Thank you especially for your example!


Best regards, Vladimir.

 
Valeriy Yastremskiy:

you are picking on me, of course the comment is incomplete, the first variableinA is as it should be, a condition of execution so to speak, and the seconda, is as it actually is)))))))))) And that's why inA is entered via an instance, and is unchangeable, and the variable a .... although yes, it shouldn't be a constant variable, but a static or just a text type))))

But it still makes sense)

OK, I may be picking on you, but still, enumerations are superfluous for a student right now. You have to remember about consistency in the curriculum. Then let's write the class at once. ))))
 
Реter Konow:
OK, I may be picking on you, but still, enumerations are unnecessary for a student right now. You have to remember about consistency in the curriculum. Then let's write the class at once. ))))

No, no, no, no!!! I'm already a mess in my head!

Respectfully, Vladimir.

 
MrBrooklin:

Hello, Peter! I'll certainly think about it! Only the whole point is that the question was asked:

"...The control question: 'enough time' - what type can this variable be, so that there are no compiler warnings...".

That's what I was trying to answer.


Sincerely, Vladimir.

Yes, hello. That's right, that was exactly the question but you haven't answered it correctly yet because the string type, in the context of the condition's contents, is incorrect. The compiler will not generate an error message or warning but the condition is defective in its meaning.
 
MrBrooklin:

No, no, no, no!!! I'm already messed up in the head!

Respectfully, Vladimir.

That's what I'm saying. No need for enumerations and unnecessary syntax now.