I'm amazed with Ruby's syntax, I can only describe it in one word: comfortable.
EDIT: I think I wasn't clear. I want an easy way to exit loops with conditions.
Sadly, I can't find how to do this Java code in Ruby:
Assume: array = [1,2,3,4] array2 = [1,2,3,4]
boolean condition = false;
for(int i = 0; i < array.length && !condition; i++)
{
for(int j = 0; j < array2.length && !condition; j++)
{
condition = (array[i] + array2[j] + 1 == 7);
}
}
if(condition)
{
System.out.println("Two elements of the arrays + 1 sum 7")
}
I love Ruby's one liners... But I can't even do this with full open loops...
I'm looking for something like this (each_while is made up):
array.each_while(condition && condition2) { SomeAction }
Which is the simplest way to do this in Ruby?
Most of the loops I work with have exiting conditions to optimize them. Everything I find on the internet is not acceptable for Ruby's beautiful syntax because it is even worse than Java, and we all know Java ain't pretty.
Some solution I found in the web:
catch "BreakOuterLoop" do
for i in 1..10
print "out #{i}\n"
for j in 1..10
print "in #{j}\n"
throw "BreakOuterLoop" if i+j > 16
end
end
end
Just awful...