実際にカロリー計算プログラムはこのようになる。while_calory.rb:
#!/usr/koeki/bin/ruby total = 0 cal = 0 while true STDERR.printf("摂取したカロリー [kcal] ( 入力終了は q ) : ") cal = gets.chomp if cal == "q" break end total += cal.to_i end printf("本日の総摂取カロリーは %d[kcal] でした\n", total)
==
\n