Self-learning the MQL5 language from scratch - page 42

 
MrBrooklin:

I continue studying the MQL5 programming language and am posting the code of a script, which is a continuation of one task from the participants of this thread. The script has been tested in all modes. No problems detected. I have set the minimum number of input parameters to start with. The script code is written in English, the comments to the code are in Russian, to facilitate the learning. As I promised earlier, I tried to describe the script in a manner accessible to a 1st class student of the programming school.

Regards, Vladimir.

ok

now make the code of the algorithmic logic more readable

it turns out in only two lines:

if(have_time()>=Period_learning && have_time()!=0 && have_patience()==true)Print("Я выучу язык MQL5!");
else Print("Я не выучу язык MQL5!");

You don't even need to comment on it.

 
Renat Akhtyamov:

ok

now make the algorithmic logic code more readable

it's only two lines:

if(have_time()>=Period_learning && have_time()!=0 && have_patience()==true)Print("Я выучу язык MQL5!");
else Print("Я не выучу язык MQL5!");

You don't even need to comment on that.

Hello, Renat! I agree, maybe I shouldn't write too many comments, but they will help all newbies with no knowledge of programming. If someone had done this work before me, the learning process would have been much faster. Comments will help to memorize my own code quicker. Perhaps the commentaries will be shorter in the future.

Regards, Vladimir.

 
Roman Shiredchenko:


Your code and logic are correct. On my IMHO, I looked yesterday, I was surprised at the zero myself at first, but then I caught up with the difference chip... :-)

Hello Roman! Yes, it is the consequence of technical education and my thinking logic is a bit different, but Peter was right about zero, so I changed the script code.

Regards, Vladimir.

 
MrBrooklin:

I continue studying the MQL5 programming language and am posting the code of a script, which is a continuation of one task from the participants of this thread. The script has been tested in all modes. No problems detected. I have set the minimum number of input parameters to start with. The script code is written in English, the comments to the code are in Russian, to facilitate the learning. As I promised earlier, I tried to describe the script in a manner accessible to a 1st class student of the programming school.

Regards, Vladimir.

Problems with logic remain:

1. Functions should calculate something. In this case, both functions initialize global variables with the value of their input variables and do nothing else. That is, if you put inpu variables in the condition, nothing will change.

2. have_time is equal to Days_passed, which is set by the user. The condition says: if(have_time() >= period_learning... which is 500, and then it says && have_time() >0... this is a logical error. If have_time() is above 500, then have_time() is already above zero, so this code is unnecessary.

3. The result of asking whether or not you will or won't learn should not depend only on the hook. You need to think of some variable with an undefined value which will affect the calculation regardless of your wishes. Otherwise, there's no question - what you entered is what you got.


P.S. If entry have_time > 0 controls thus value of peroid_lerning, in case of entering negative value or zero, it is more correct to put in condition && period_learning > 0.
 
Fast235:

First, learn how to work with string variables from Dmitry Fedoseyev, infostringements are very foggy at the stage of studying other people's code,

The article he reviewed makes everything clear, and you will learn some of the details in passing, I'm speaking as a reader of most articles here, I think no one has read more than me)

Hello, thanks for the tip. I read Dmitry Fedoseyev's articles, but so far I'm having a hard time learning from his articles, as I have no basic training. Hopefully it will get easier. By the way, writing the Learning_MQL5.mq5 script helped me seriously to understand what a function is, what it is good for and how it is created!

Best regards, Vladimir.

 
Реter Konow:
The problems with logic remain:

1. The functions have to calculate something. In this case, both functions initialize the global variables with the value of the pip variables and do nothing else. That is, if you put inpu variables in the condition, nothing will change.

2. Have_time equals Days_passed, which is set by the user. The condition says: if(have_time() >= period_learning... which is 500, and then it says && have_time() >0... this is a logical error. If have_time() is above 500, then have_time() is already above zero, so this code is unnecessary.

3. The result of asking whether or not you will or won't learn should not depend only on the hook. You need to think of some variable with an undefined value which will affect the calculation regardless of your desire. Otherwise, there's no question - what you input is what you get.

Hello Peter! Knew you would have questions, especially on point 2.

The code here is not superfluous, but very clever. If you try to remove && have_time()!=0(you have written it as && have_time()>0) from the script code, the result will be "I will learn MQL5!" given the input parameters Period_learning=0 and Days_passed=0, and this is not permissible from the dogics viewpoint!

I agree with the other points - there is a lot to think about.

Regards, Vladimir.

 
MrBrooklin:

Hello Peter! I knew you would have questions, especially on point 2.

The code here is not superfluous, but quite elaborate. If you try to remove && have_time()!=0(you wrote it as && have_time()>0) from the script code, the result will be "I will learn MQL5!" given the input parameters Period_learning=0 and Days_passed=0, and this is not permissible from the dogics viewpoint!

I agree with the other points - there is a lot to think about.

Regards, Vladimir.

Ok, look: have_time() essentially returns the value of the Days_passed inpu variable. If Days_passed is set to zero, the entry if(...have_time()!=0... will not pass us into the condition, but if Period_learning is set to zero, we will pass into the condition. So, writing Period_learning >0 will simultaneously protect us from zero in the Days_passed variable and from zero in the Period_learning variable, while writing if(... have_time()!=0 ... only against zero in Days_passed).
 
Реter Konow:
Ok, look: the have_time() function essentially returns the value of the Days_passed input variable. If Days_passed is zero, then the entry if(...have_time()!=0... will not let us pass into the condition, but if Period_learning is zero, we will pass into the condition. So, writing Period_learning >0 will simultaneously protect us from zero in the Days_passed variable and from zero in the Period_learning variable, while writing if(... have_time()!=0 ... only against zero in Days_passed).

I see.

Respectfully, Vladimir.

 
MrBrooklin:

I see.

Regards, Vladimir.

In the main, of course, you've taken a big step forward - you've mastered and started using the functions, and congratulations are in order!)

At this rate, you'll soon be trailing.

P.S. Sorry for not saying hello. People don't usually say hello here on the forum, which of course should not be taken as a sign of disrespect. I remember about five years ago a moderator reprimanded me when I said hello to forum members. )) Since then, I don't say hello here, only in private. Sorry again.)))
 
Реter Konow:
You have certainly made a serious step forward in the main - you have mastered and begun to use the functions, for which you are to be congratulated, of course!)

At this rate, you'll soon be trailing.

P.S. Sorry for not saying hello. People don't usually say hello here on the forum, which of course should not be taken as a sign of disrespect. I remember about five years ago a moderator reprimanded me when I said hello to forum members. )) Since then, I don't say hello here, only in private. Sorry again)))

Thanks, Peter, for the words of encouragement!

As for polite conversations, especially greeting and wishing everyone good day and good mood. In my opinion it's very lacking in the forum. Respectful treatment of interlocutors is something our generation has been taught since Soviet times. If the administration of the site (forum) would reprimand me regarding welcoming to participants, I will take it into account and follow the rules.

Regards, Vladimir.