until (condition)
dosomething
end
-------------------------------------------------------------------------------------
for number in number1...number2
dosomething
end
will dosomething with the number from number1 to (number2)-1 (ex. number1= 0, number2 = 10 and dosomething: puts number)
... means exclusive of the upper bound.
.. means inclusive of the upper bound.
-------------------------------------------------------------------------------------
i = 20
loop do
i -= 1
print "#{i}"
break if i <= 0
end
the section inside 'do' and 'end' actually represent { } each for a loop. For example, a loop could be:
loop { dosomething }
-------------------------------------------------------------------------------------
next if somethingIDontWant
is equivalent to if(somethingIDontWant) continue; in c++ or java.
-------------------------------------------------------------------------------------
my_array = [1, 2, 3, 4, 5]
-------------------------------------------------------------------------------------
array = [1,2,3,4,5]
array.each do |x|
x += 10
print "#{x}"
end
is equivalent to:
int array = {1, 2, 3, 4, 5};
for(int each : array){
each += 10;
System.out.print(each);
}
dosomething
end
-------------------------------------------------------------------------------------
for number in number1...number2
dosomething
end
will dosomething with the number from number1 to (number2)-1 (ex. number1= 0, number2 = 10 and dosomething: puts number)
... means exclusive of the upper bound.
.. means inclusive of the upper bound.
-------------------------------------------------------------------------------------
i = 20
loop do
i -= 1
print "#{i}"
break if i <= 0
end
the section inside 'do' and 'end' actually represent { } each for a loop. For example, a loop could be:
loop { dosomething }
-------------------------------------------------------------------------------------
next if somethingIDontWant
is equivalent to if(somethingIDontWant) continue; in c++ or java.
-------------------------------------------------------------------------------------
my_array = [1, 2, 3, 4, 5]
-------------------------------------------------------------------------------------
array = [1,2,3,4,5]
array.each do |x|
x += 10
print "#{x}"
end
is equivalent to:
int array = {1, 2, 3, 4, 5};
for(int each : array){
each += 10;
System.out.print(each);
}