A bit more in-depth of what's happening in the VM:
Doing something like this simply results in fewer opcodes to be executed and thus makes your code more optimal.
Code: Select all
myInt = 50;
bSomeBool = (myInt >= 10 || myInt < 5) && myInt < 100;
So what's actually happening here?
Let's start looking at the structure of an operator.
An operator can take as most two operands and every operator in this line returns a boolean.
Code: Select all
native(153) static final operator(24) bool >= ( int A, int B );
native(150) static final operator(24) bool < ( int A, int B );
So in order to evaluate the result of the && operator, the right-hand and left-hand operands has to be evaluated.
Now the right-hand operand has a single operator argument where no additional operands has to be evaluated.
On the left-hand we have an additional level of operators, which means in order to evaluate '&&' we have to evaluate '||' , in order to evaluate '||'
we have to evaluate its corresponding resulting operands 'myInt >= 10 ' and 'myInt < 5'.
So when every operator successfully evaluates its operands it pushes the result onto the variable stack of the VM.
That in turn means that the previous operator in the hierarchy then pops the first variable off of the stack (which was the result) so it can then re-evaluate that with the new conditions, and Mary goes around...
So what happens in your code is that the assignment operator takes the result of the evaluated '>' operator, pops it off of the stack and assigns it to the boolean variable.
If you take a close look at the return type of the operators they all return a boolean, so there is no type mismatch and therefore completely legal.
An if statement takes a single boolean operand, which is the result of the operators used as an argument.
Like Sektor2111 said, any variable can be easily output to the console, because the engine automatically coerces any incoming data type to a string, which the engine performs specific type conversions on, all happening under the hood.