ruby推送示例_Ruby直到示例循环
ruby推送示例
直到循環(huán) (The until loop)
The until loop is one of the great features of Ruby which makes it different from other programming languages. The support of until loop specifies how much user-friendly language Ruby is?
直到循環(huán)是Ruby的重要功能之一,這使其與其他編程語言有所不同。 對直到循環(huán)的支持指定了Ruby用戶友好語言是多少?
The until loop is just the opposite of while loop if we justify it in terms of functionality. while loop is executed as long as the Boolean condition stands to be false but in case of until loop, it executes as long as the Boolean condition does not come out to be true. It is the example of the entry-control loop where the specified condition is checked prior to the execution of the loop's body.
如果我們從功能上證明它,則直到循環(huán)與while循環(huán)正好相反。 while循環(huán)是只要布爾條件成立的情況是假的,但直到循環(huán)的情況下執(zhí)行,因?yàn)椴紶枟l件不出來是真實(shí)的它執(zhí)行長。 這是進(jìn)入控制循環(huán)的示例,其中在執(zhí)行循環(huán)主體之前檢查指定的條件。
The until loop is implemented with the help of the following syntax:
使用以下語法可以實(shí)現(xiàn)直到循環(huán) :
until conditional [do]# code to be executedendExample 1:
范例1:
=begin Ruby program to print a message 10 times using until loop =endnum=0until num==10puts "Hello there! Message from Includehelp.com! Happy learning!"num=num+1 endOutput
輸出量
Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning! Hello there! Message from Includehelp.com! Happy learning!Example 2:
范例2:
=begin Ruby program to find the sum of all digits of given number using until loop =endputs "Enter the number" num=gets.chomp.to_itemp=num sum = 0until num==0#implementation of until looprem=num%10num=num/10sum=sum+rem endputs "The sum of #{temp} is #{sum}"Output
輸出量
Enter the number 456672 The sum of 456672 is 30Example 3:
范例3:
=begin Ruby program to find the count of even and odd digits in the given number using until loop =endputs "Enter the number" num=gets.chomp.to_itemp=num evecount=0 oddcount=0until num==0#implementation of until looprem=num%10num=num/10if rem%2==0puts "#{rem} is even"evecount+=1elseputs "#{rem} is odd"oddcount+=1end endputs "Number of even numbers are #{evecount}" puts "Number of odd numbers are #{oddcount}"Output
輸出量
Enter the number 7896532 2 is even 3 is odd 5 is odd 6 is even 9 is odd 8 is even 7 is odd Number of even numbers are 3 Number of odd numbers are 4翻譯自: https://www.includehelp.com/ruby/until-loop.aspx
ruby推送示例
總結(jié)
以上是生活随笔為你收集整理的ruby推送示例_Ruby直到示例循环的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lcfirst_PHP lcfirst(
- 下一篇: java settime_Java日历s