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 6657009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:42:50+00:00 2026-05-26T01:42:50+00:00

So here I am with this simple question Consider these two for cycles and

  • 0

So here I am with this simple question

Consider these two for cycles and please
explain to me if there’s any difference
between the two ways of writing

method 1 :

  for(i=(max-1) ; i>=0 ; i--){ do-some-stuff }

method 2 :

  for(i=max ; i>0 ; i--)     { do-some-stuff }

the reason I’m asking this is because today at school
while we were seeing some Java functions, there was
this palindrome method wich would use as max the
length of the word passed to it and the method used
to cycle trough the for was the first, can anyone
clarify me why the person who writed that piece of
code prefeered using that method ?

  • 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-05-26T01:42:51+00:00Added an answer on May 26, 2026 at 1:42 am

    Yes, there’s a big difference – in the version, the range is [0, max-1]. In the second version, it’s [1, max]. If you’re trying to access a 0-based array with max elements, for example, the second version will blow up and the first won’t.

    If the order in which the loop ran didn’t matter, I’d personally use the more idiomatic ascending sequence:

    for (int i = 0; i < max; i++)
    

    … but when descending, the first form gives the same range of values as this, just in the opposite order.

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

Sidebar

Related Questions

I'm pretty sure this is a simple question in regards to formatting but here's
Ok so this maybe a simple/silly question but I don't know so here goes:
im struggling with syntax here: hopefully this question is v simple, im just miising
Here's a simple (hopefully) L10N question: Do all locales want this format: Sunday, Nov
this is probably too simple of a question, but here I go. I have
This is similar to (but different from) this question . Here is some simple
Consider this simple XML document. The serialized XML shown here is the result of
This might be a entity framework related question, anyway, here goes: Consider the following
There's this question but it has nothing close to help me out here. Tried
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });

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.