1
0

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.

Ruby 分岐ごとのカウントについて

Posted at

Xを変数として①の条件により+1or-1を追加していき、Xの偏りが+5or-5になったら②or③に移行する。そして②、③に移行して条件をクリアしたらリセットされてまたループするというコードを書きたいのですがうまくいきません。
ここまでは雰囲気で書いたのですが思い通りに動いてくれません、いい方法ありませんか?よろしくお願いします。

loop do
X = 0
---------------------------------------------①
if ほげほげ
X = X - 1
elsif ほげほげ
X = X + 1
--------------------------------------------------②
if X > 5
X = X - 5
------------------------------------------------- ③
if X < -5
X = X + 5

end

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?