Summary of circular statements in Ruby

Source: Internet
Author: User

This article mainly introduces the circulation statement summary in Ruby, this article summarizes some commonly used in Ruby the cyclic syntax, the need friend may refer to the next

while (when ...) ) loop

 

 

While condition

Statement 1; Statement 2; Statement...

End

Single While loop

(statement 1; Statement 2; Statement... ) While condition

Until (until ...) ) loop

Until condition = While not (condition)

For...in cycle

 

 

For variable in object

Statement 1; Statement 2; Statement...

End

Break

Jump out of the loop when the layer

Next

Ignore the rest of the cycle and start the next loop

Redo

Start the cycle again, or from this time

Retry

Start over, this cycle body.

Times

3.times {print "hi!"} #Hi! Hi! Hi!

Upto

1.upto (9) {|i| print i if i<7} #123456

Downto

9.downto (1) {|i| print i if i<7} #654321

each

(1..9). Each {|i| print i if i<7} #123456

Step

0.step (11,3) {|i| Print i} #0369

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.