ruby-LEDの日記

2006-06-24

[]文修飾子

  • if文
irb(main):001:0> radiation = 3000
=> 3000
irb(main):002:0> puts "Danger, Will Robinson" if radiation > 3000
=> nil
irb(main):003:0> puts "Danger, Will Robinson" if radiation > 2999
Danger, Will Robinson
=> nil
  • while文
irb(main):004:0> square = 2
=> 2
irb(main):005:0> p square = square*square while square < 1000
4
16
256
65536
=> nil
  • 処理の後ろに条件が書けるのですね。
$ radiation=3000
$ [ $radiation=3000 ] && echo "Danger, Will Robinson"
Danger, Will Robinson
トラックバック - http://rubyist.g.hatena.ne.jp/ruby-LED/20060624