2008/4/17, Iki Baz Castillo <ibc / aliax.net>:
> 2008/4/17, Stefan Lang <perfectly.normal.hacker / gmail.com>:
>
>
>  > break is only for iteration. What are you trying to do?
>  >  The example you've given is not a compelling use case,
>  >  since you can simply remove the line after break.
>
>
> Ok, I write a better example:
>
>
>   var = ...something...
>
>   case num
>   when 1:
>     puts "var not valid !!!!!" if ( var < 0 || var > 10 )
>     break
>     do_normal_stuff
>     ...
>     ...
>     end_normal_stuff
>   end
>
>   puts "Write it"
>
>
>  I just want do_normal_stuff in case "var" is valid.
>  Yes, I can put a big "if" stament and so but I would like not to do it
>  since it makes a bit ugly the code.

Well, since Ruby doesn't support it, you must find other
ways to structure the code in each case. Exceptions might
help in the bigger picture, splitting it up in smaller methods, etc.

You can use catch/throw for this:

    catch(:invalid_var) {
      case num
      when 1
        if var < 0 || var > 10
          puts "var not valid !!!!!"
          throw(:invalid_var)
        end
        do_normal_stuff
        ...
        ...
        end_normal_stuff
      end
    }
    puts "Write it"

But be careful, catch/throw is dynamically scoped.
"ri catch" has more info.

Stefan