Andrei Iakovlev #: Is there some way to choose which loop to use depending on the value of the bool variable?
// search elements from first to last in the required direction, depending on whether last is greater or less than firstfor( int i=first, increment=(last>=first?1:-1) ;
i!=last+increment ;
i+=increment ) {
...
}
Is there any way to choose which loop to use depending on the value of the bool variable? Inside the loops everything is the same, so I want to select the loop itself 1 time.
The error occurs due to the fact that before compilation you substitute the names specified after #define with the names specified next in this directive.
That is why your variant unfolded in:
if(Up)
for(i = 21; i >= start; i--)
elsefor(i = start; i < 22; i++) {
//...
}
There is no loop body after the first for(), but else immediately follows. This is what is reported in the error.
I didn't know that the conditional operator ? : in the 2nd and 3rd operands you can use expressions of relation operations, and I didn't realise to check it. I've been wondering for a long time how you can quickly change ">" to "<".
bool h = true; char g = 3, q = 4;
Print((h ? g > q : g < q) ? 5 : 6);
I didn't know that in the conditional operator ? : in the 2nd and 3rd operands you can use expressions of relation operations, but I didn't realise to check it. I've been wondering for a long time how you can quickly change ">" to "<".
As far as I remember, in a ternary operator in the last two operands you can use any expression of any complexity, the result of which will be values of the same type. In this example, there are two expressions that turn into logical values. But "can" does not always mean "must". That is, sometimes it is better to write more lines of code that will be more understandable to a human than a cumbersome construct with ternary operators. But here everyone decides for himself how it is more convenient for him.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Is there some way to choose which loop to use depending on the value of the bool variable?
something like this :-)
Interesting implementation, thanks.
That's the way to do it too:
Is there any way to choose which loop to use depending on the value of the bool variable? Inside the loops everything is the same, so I want to select the loop itself 1 time.
This option causes an error
The error occurs due to the fact that before compilation you substitute the names specified after #define with the names specified next in this directive.
That is why your variant unfolded in:
There is no loop body after the first for(), but else immediately follows. This is what is reported in the error.There is no loop body after the first for(), but else comes right after it. This is what is reported in the error.
I understand.
up ? i >= start : i < end
I didn't know that the conditional operator ? : in the 2nd and 3rd operands you can use expressions of relation operations, and I didn't realise to check it. I've been wondering for a long time how you can quickly change ">" to "<".
I didn't know that in the conditional operator ? : in the 2nd and 3rd operands you can use expressions of relation operations, but I didn't realise to check it. I've been wondering for a long time how you can quickly change ">" to "<".
Friends, please remind me, somewhere I read about constructors and destructors. The order of creation and destruction, but I can't find it....
Should a parent's constructor be called in a descendant?
Should the parent's destructor be called in the descendant?
Please show some examples, especially about destructor.
Friends, please remind me, somewhere I read about constructors and destructors. The order of creation and destruction, but I can't find it....
Should the parent's constructor be called in the descendant?
Should the parent's destructor be called in the descendant?
Please show some examples, especially about destructor.
In the descendant you must specify which of the parent's constructors is used.
class Child: public Parent {
// construct
Child(double arg):Parent() {
}
// copy cons
Child(const Child &orig):Parent(orig) {
}
~Child() {
}
}
You don't need to write or specify anything like that in destructors
Does the parent's constructor need to be called in the descendant?
Should the parent's destructor be called in the descendant?
Write this line in all constructors/destructors.
Then you will see the sequence of all calls in the log. And the picture will be formed.