Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8257239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:07:52+00:00 2026-06-08T02:07:52+00:00

How can I express the next for loops in a rubysh way? for (r

  • 0

How can I express the next for loops in a rubysh way?

for (r = 1; r < R; r++) {
    for (i = 0; i < 4; i++) {
            #do something
            }
}

I want to express the above code with an elegant ruby syntax.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:07:55+00:00Added an answer on June 8, 2026 at 2:07 am

    By default, the way I’d write that in Ruby is this:

    for r in 1..(R-1) do
      for i in 0..3 do
        # Do something
      end
    end
    

    But an even better way is to take advantage of the Range feature pointed out by @PedroNascimento in his answer, using three dots rather than two in order to leave the last item out of the Range:

    for r in 1...R do
      for i in 0...4 do
        # Do something
      end
    end
    

    That’s both nicer to look at and more clearly expresses the meaning of the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can i express in xpath a) need select elements which contains specified keyword.
Can I deploy SQL Server Express with my desktop application just like builtin database?
Can I develop Silverlight applications in Visual Studio express? When I start up Visual
Can AnkhSVN be installed on an Express edition of Visual Studio?
I can't create New Project on my Visual Web Developer 2008 Express with SP1.
TFS Express 11 beta installation also includes SQL Express installation for its database. Can
UPDATE: After updating to stylus 0.7.4 and express 2.3.12 I can no longer reproduce
I'm having trouble accessing my IIS 7.5 express site in FireFox but i can
I'm pretty darn new to C# and I can't figure out how to express
I'm wondering if I can use SQL Server CE instead of SQL Server Express+

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.