私のプログラムで、私のプログラムに「終了」マーカーが多すぎる/していないというエラーが多かったです。私は前にこのコードをテストしていますが、動作しますが、if文またはtoo manyに十分な "end"があるかどうかを誰かが教えてくれるかどうかは疑問です。 !おかげruby method:ifステートメント内のステートメント
はデフホップ(d)の自動字下げをサポートしているテキストエディタで
if d== 0
if @current_location.addpoint(0,1) < @boundary1
puts "error"
elsif if @current_location.addpoint(0,1) > @boundary2
puts "error2"
else
@current_location= @current_location.addpoint(0,1)
puts "all good"
end
end
elsif d == 1
if @current_location.addpoint(0,-1) < @boundary1
puts "error"
elsif if @current_location.addpoint(0,-1) > @boundary2
puts "error2"
else
@current_location= @current_location.addpoint(0,-1)
puts "all good"
end
end
elsif d== 2
if @current_location.addpoint(1,0) < @boundary1
puts "error"
elsif if @current_location.addpoint(1,0) > @boundary2
puts "error2"
else
@current_location= @current_location.addpoint(1,0)
puts "all good"
end
end
else d= 3
if @current_location.addpoint(-1,0) < @boundary1
puts "error"
elsif if @current_location.addpoint(-1,0) > @boundary2
puts "error2"
else
@current_location= @current_location.addpoint(-1,0)
puts "all good"
end
end
end
Rubyの規約に従えば、この問題に直面することはありません。 – Bohdan
"if-in-if"条件の結果を変数に代入することで、読み込みを簡単にすることができます。あなたのコードに大きな利益をもたらすでしょう! – Romain