ネストされたif文について

Kazunori Kamiya
Aug 24, 2017 · 2 min read

・Exercise31:断を下す

ここでは前回までで学習したifやelsif、elseを使ってスクリプト内で物事を決定するということをやっていきます。

このスクリプトでは、ユーザーに質問をしてその答えに基づいて断を下していきます。

ここでのポイントはif文の中にif文を入れていることで、これも問題なく実行できます。
これはネストされた質問を作る際に非常に有効なものであり、1つのブランチからいくつものブランチに繋げることができます。

出力結果について

例えば、以下のようになります。

学習ドリル

  1. 上のゲームに、新たなパートを作成して動かしてみてください。
  2. 全く新しいゲームを作成してみてください。

学習ドリルの答え

  1. ドアが2つだったのを、3つにしてみました。

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade