LoginSignup
0
0

More than 1 year has passed since last update.

while true do の使い方

Last updated at Posted at 2021-05-14

whileの使い方

ex1.条件によって繰り返し処理を行う場合

while 条件式 do
  処理するアクション
end

ex2.プログラムを終了させず同じ処理を繰り返すループ処理を行う場合

while true do
  処理するアクション
end

問題.1
以下の仕様を満たすアプリケーションを作成してください。
仕様
プログラムの実行を行うと、
①「[0]:体重を表示する、[1]:終了する」という選択肢が表示され、数字を入力することができる
② 0を入力すると「80kg」と表示され、上記条件①が繰り返し実行される。
③ 1を入力するとアプリケーションが終了する

while true do
  puts "[0]:体重を表示する"
  puts "[1]:終了する"
  input = gets.to_i
  if input == 0
    puts "80kg"
  elsif input == 1
    exit
  end
end

0
0
0

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