Summary of loop statements in ruby and summary of ruby loop statements

Source: Internet
Author: User

Summary of loop statements in ruby and summary of ruby loop statements

While (when ...) Loop

 

 

While Condition

Statement 1; Statement 2; statement...

End

Single Row while LOOP

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

Until (...) Loop

Until condition = while not (condition)

For... In Loop

 

 

For variable in object

Statement 1; Statement 2; statement...

End

Break

Jump out of layer Loop

Next

Ignore the remaining part of this loop and start the next loop

Redo

Start the loop again, or start from this time

Retry

Start the loop body again

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

(123456). each {| I | print I if I <7} #

Step

0. step (0369) {| I | print I} #

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.