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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ruby推送示例_Ruby for循环示例

發(fā)布時(shí)間:2023/12/1 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ruby推送示例_Ruby for循环示例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

ruby推送示例

for循環(huán) (The for loop)

In programming, for loop is a kind of iteration statement which allows the block to be iterated repeatedly as long as the specified condition is not met or a specific number of times that the programmer knows beforehand. A for loop is made of two parts:

在編程中, for循環(huán)是一種迭代語(yǔ)句,只要不滿足指定條件或程序員事先知道的特定次數(shù),就可以重復(fù)迭代該塊。 for循環(huán)由兩部分組成:

  • The header part

    標(biāo)頭部分

  • The actual body

    實(shí)際的身體

  • The header part is used to specify the number of iterations. Most of the times it explicitly mentions the count of iterations with the help of a variable. for loop is generally used when the number of iterations is explicitly known before the execution of the statement declared within its block. The actual body contains the expressions or statements which will be implemented once per repetition.

    標(biāo)頭部分用于指定迭代次數(shù)。 在大多數(shù)情況下,它借助變量明確提及迭代次數(shù)。 當(dāng)在其塊內(nèi)聲明的語(yǔ)句執(zhí)行之前明確知道迭代次數(shù)時(shí),通常使用for循環(huán) 。 實(shí)際主體包含將重復(fù)執(zhí)行一次的表達(dá)式或語(yǔ)句。

    It is a kind of Entry control loop. Generally, you can easily make an infinite loop through for loop by using the following syntax:

    這是一種Entry控制循環(huán)。 通常,您可以使用以下語(yǔ)法輕松地通過for循環(huán)進(jìn)行無(wú)限循環(huán):

    for(;;){#body}

    In Ruby, for loop is implemented with the help of the following syntax:

    在Ruby中, for循環(huán)是通過以下語(yǔ)法實(shí)現(xiàn)的:

    for variable_name[, variable...] in expression [do]# code to be executedend

    Example 1:

    范例1:

    =begin Ruby program to print the table of the number specified by the user using for loop =endputs "Enter a number" num=gets.chomp.to_ifor i in 1..10 #implementation of for loop for #pre-specified range 1..10k=i*numputs "#{num} * #{i} = #{k}"i+=1 #incrementing the counter variable end

    Output

    輸出量

    Enter a number 89 89 * 1 = 89 89 * 2 = 178 89 * 3 = 267 89 * 4 = 356 89 * 5 = 445 89 * 6 = 534 89 * 7 = 623 89 * 8 = 712 89 * 9 = 801 89 * 10 = 890

    Example 2:

    范例2:

    =begin Ruby program to print the list of the odd and even numbers where the lower limit is specified by the user and the upper limit is 100 using for loop =endputs "Enter the lower limit(ul is 100)" num=gets.chomp.to_iif (num>=100) #lower limit can not be #equal to or greater than upper limit puts "Invalid lower limit" elsefor i in num..100 #implementation of for loop for #pre-specified range num..100if (i%2==0)puts "#{i} is even"elseputs "#{i} is odd"endi=i+1 #incrementing the counter variableend end

    Output

    輸出量

    First run: Enter the lower limit 76 76 is even 77 is odd 78 is even 79 is odd 80 is even 81 is odd 82 is even 83 is odd 84 is even 85 is odd 86 is even 87 is odd 88 is even 89 is odd 90 is even 91 is odd 92 is even 93 is odd 94 is even 95 is odd 96 is even 97 is odd 98 is even 99 is odd 100 is evenSecond run: Enter the lower limit 900 Invalid lower limit

    The for loop is one of the most commonly used loops in programming. As it is preferable and has easy syntax.

    for循環(huán)是編程中最常用的循環(huán)之一。 最好是它并且語(yǔ)法簡(jiǎn)單。

    翻譯自: https://www.includehelp.com/ruby/for-loop.aspx

    ruby推送示例

    總結(jié)

    以上是生活随笔為你收集整理的ruby推送示例_Ruby for循环示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。