Ruby has a three loop controlling command : Break , Next and Redo ,while the Break and the Next command has equivalents in all other languages Redo is unique to Ruby .
Redo acts like next except it doesn't evaluate the while condition .
example:
1: while line = gets
2: puts line
3: break if line =~ /^STOP/ # stop at end
4: redo if line.gsub!(/^STO/) { line = 'STOP'}
5: end
The result :
ee
ee
sto
sto
STO
STO
STOP
אין תגובות:
הוסף רשומת תגובה