Uncle bearded need help on the trigger.
In the book "Ruby Programming Language" authors Matsumoto, Flanagan have the code:
(1..10).each {|х| print х if х==3..х==5 } The output of the following 345 goes further nonsense:
A trigger consists of two Boolean expressions united by an operator .., in the context of a condition or loop. The trigger expression is evaluated to false as long as the left expression evaluates to true (maybe it should be false).
As soon as this expression becomes true , the expression "flips" to the steady state true . It will remain in this state, and subsequent calculations will return true until the right expression evaluates to true (it may have to until the right expression evaluates to true).
When this happens, the trigger is "thrown" back to the steady state false . Subsequent evaluations of the expression return false until the left expression is again true .
About the trigger with 3 points translation is even worse.
The difference is that when using the operator .. when the trigger is thrown to true, it returns true, but it also tests its right expression to see if it should not relocate its internal state back to false. When using the ... operator, the right expression is first tested.
(1..10).each {|х| print х if х==3..х==5 } - left expression 1, 2 == 3 ( false ) state: false
- the left expression 3 == 3 ( true ) changes the state to: true returns true , the right side is checked ( false ).
- left expression 4 == 3 ( false ) state remains: true as right expression 4 == 5 false
- the left expression 5 == 3 ( false ) the state remains: true, the test of the right expression 5 == 5 ( true ) is reset to the state false .
6,7,8,9,10 == 3 ( false ) state does not change.
Well, with ... dots, I'm confused. If that is not strictly judged, please understand and forgive.