13.9.2009

Next - the new rubyword for today

I learned a new word in ruby today while reading the brilliant Ruby Quiz, namely quiz #162 - The Turing Machine.

'Next' works with loops like '.each' or '.times', starting the next iteration of the loop. It is useful for conditionally ending the current iteration.
File.open(file).each_line do |line|
line.gsub!(/#.*/, '') # remove comments
next if line =~ /^\s*$/ # skip blank lines

line = line.split(/\s+/)
@state = line[0] if @state.nil?
@program[line[0..1]] = line[2..4]
end

Funny, but next hadn't stuck on me before. Maybe this time.