Just out of curiousity, does Groovy have an equivalent to Ruby's flip-flop operator?

i = 0
while i < 10
  puts i if (i == 3)...(i == 8)
  i += 1
end

[output]
3
4
5
6
7
8
[/output]

The basic structure of the flip-flop is

(<on condition>)..[.](<off condition>)

It represents a temporary variable that is flipped true when the first condition becomes true and flips false when the second condition becomes true. Used as above for snipping out ranges of elements in a list based on start/end conditions.

The non-flip-flop code would look something like this:

i = 0
switch = false
while i < 10
  if switch
    switch = !(i == 8)
  else
    switch = (i == 3)
  end
  puts i if switch
  i += 1
end

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to