日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ruby 嵌套函数_Ruby嵌套直到循环带有示例

發布時間:2023/12/1 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ruby 嵌套函数_Ruby嵌套直到循环带有示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ruby 嵌套函數

嵌套直到循環 (Nested until loop)

Alike for, while, and do...while, until loop can also be nested for meeting the specific purpose. In this type of nesting, two until loops work in the combination such that at first, the outer loop is triggered which results in the execution of the inner loop. The outer Until loop is not invoked as long as the inner loop does not comes out to be true. It is a kind of Entry control loop which simply means that first the outer Boolean expression is processed; if it is false then the pointer will move to the inner loop to check inner condition. The whole execution will take place in the same manner.

與for, while和do ... while一樣 , 直到循環也可以嵌套以滿足特定目的。 在這種嵌套中,兩個直到循環在組合中起作用,這樣一來,首先觸發外循環,從而執行內循環。 只要內部循環不成立,就不會調用外部的直到循環。 這是一種Entry控制循環,僅表示首先處理外部布爾表達式;然后進行處理。 如果為假,則指針將移至內部循環以檢查內部條件。 整個執行將以相同的方式進行。

Syntax:

句法:

until conditional [do]until conditional [do]# code to be executedend # code to be executedend

Example 1:

范例1:

=begin Ruby program to find the sum of numbers lying between two limits using nested until loop =endputs "Enter the Upper limit" ul=gets.chomp.to_i puts "Enter the Lower limit" ll=gets.chomp.to_iuntil ul==llnum=ultemp=ulsum = 0until num==0#implementation of until looprem=num%10num=num/10sum=sum+remendputs "The sum of #{temp} is #{sum}"ul=ul-1 end

Output

輸出量

Enter the Upper limit 1000 Enter the Lower limit 980 The sum of 1000 is 1 The sum of 999 is 27 The sum of 998 is 26 The sum of 997 is 25 The sum of 996 is 24 The sum of 995 is 23 The sum of 994 is 22 The sum of 993 is 21 The sum of 992 is 20 The sum of 991 is 19 The sum of 990 is 18 The sum of 989 is 26 The sum of 988 is 25 The sum of 987 is 24 The sum of 986 is 23 The sum of 985 is 22 The sum of 984 is 21 The sum of 983 is 20 The sum of 982 is 19 The sum of 981 is 18

Example 2:

范例2:

Pattern printing: Print the following pattern

圖案打印:打印以下圖案

001012012301234

Code:

碼:

=begin Ruby program to print the given pattern. =endnum=0until (num==6)j=0until(j==num)print jj+=1endputs ""num+=1 end

翻譯自: https://www.includehelp.com/ruby/nested-until-loop-with-examples.aspx

ruby 嵌套函數

總結

以上是生活随笔為你收集整理的ruby 嵌套函数_Ruby嵌套直到循环带有示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。