第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Ruby中是否有“ do…while”循環(huán)?

Ruby中是否有“ do…while”循環(huán)?

手掌心 2019-11-21 15:12:17
我正在使用以下代碼讓用戶輸入名稱,而程序?qū)⑺鼈兇鎯?chǔ)在數(shù)組中,直到他們輸入一個(gè)空字符串(他們必須在每個(gè)名稱之后按Enter):people = []info = 'a' # must fill variable with something, otherwise loop won't executewhile not info.empty?    info = gets.chomp    people += [Person.new(info)] if not info.empty?end這段代碼在do ... while循環(huán)中看起來會(huì)更好:people = []do    info = gets.chomp    people += [Person.new(info)] if not info.empty?while not info.empty?在此代碼中,我不必將信息分配給一些隨機(jī)字符串。不幸的是,Ruby中似乎不存在這種類型的循環(huán)。有人可以建議一種更好的方法嗎?
查看完整描述

3 回答

?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊

注意:


該begin <code> end while <condition>由Ruby的作者M(jìn)atz的拒絕。相反,他建議使用Kernel#loop,例如


loop do 

  # some code here

  break if <condition>

end 

這是2005年11月23日的電子郵件交流,其中Matz說:


|> Don't use it please.  I'm regretting this feature, and I'd like to

|> remove it in the future if it's possible.

|

|I'm surprised.  What do you regret about it?


Because it's hard for users to tell


  begin <code> end while <cond>


works differently from


  <code> while <cond>

RosettaCode Wiki具有類似的故事:


在2005年11月,Ruby的創(chuàng)建者M(jìn)atsuki Yukihiro Matsumoto對(duì)這個(gè)循環(huán)功能感到遺憾,并建議使用Kernel#loop。


查看完整回答
反對(duì) 回復(fù) 2019-11-21
  • 3 回答
  • 0 關(guān)注
  • 737 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)