1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Bash while による無限ループをマジックナンバー無しで

Last updated at Posted at 2019-06-16

AtCoder の Some Sums を解いてみているのですが、その中で新しく知ったことをメモ。
個人的に競技プログラミングに深入りするつもりはありませんが、いろいろ調べるようになって新しいことを知れるので、その面は楽しんでいます。

無限ループにするには

今までこう書くことが多かった

C なんかでも whlie (true) ってすることは多いかと思いますが、そのノリです。

while [ 1 ]; do
  hogehoge
  if [ <condition is truthy> ]; then
    break
  fi
done

ヌルコマンドの活用

1 というマジックナンバーが不要になるので、こちらの方がいいかも。

while :; do
  hogehoge
  if [ <condition> ]; then
    break
  fi
done
1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?