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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:16:58+00:00 2026-06-14T12:16:58+00:00

How to increment the outer iterator from the inner loop? To be more precise:

  • 0

How to increment the outer iterator from the inner loop?

To be more precise:

  for i in range(0,6):
    print i
    for j in range(0,5):
      i = i+2

I am getting

0
1
2
3
4
5

, but I want 0,2,4

Above is the simpilfied idea what I want to acheive.

Here is my Java code:

str1="ababa"
str2="aba"
for(int i =0; i < str1.length; i++)
  for(int j =0; j < str2.length; j++)
       if str1[i+j]!=str[j]
           break;
       if( j ==str2.length -1)
           i=i+str2.length;
  • 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-14T12:16:59+00:00Added an answer on June 14, 2026 at 12:16 pm

    It seems that you want to use step parameter of range function. From documentation:

    range(start, stop[, step]) This is a versatile function to create
    lists containing arithmetic progressions. It is most often used in for
    loops. The arguments must be plain integers. If the step argument is
    omitted, it defaults to 1. If the start argument is omitted, it
    defaults to 0. The full form returns a list of plain integers [start,
    start + step, start + 2 * step, …]. If step is positive, the last
    element is the largest start + i * step less than stop; if step is
    negative, the last element is the smallest start + i * step greater
    than stop. step must not be zero (or else ValueError is raised).
    Example:

     >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     >>> range(1, 11) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     >>> range(0, 30, 5) [0, 5, 10, 15, 20, 25]
     >>> range(0, 10, 3) [0, 3, 6, 9]
     >>> range(0, -10, -1) [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
     >>> range(0) []
     >>> range(1, 0) []
    

    In your case to get [0,2,4] you can use:

    range(0,6,2)
    

    OR in your case when is a var:

    idx = None
    for i in range(len(str1)):
        if idx and i < idx:
            continue
        for j in range(len(str2)):
            if str1[i+j] != str2[j]:
                break
        else:
            idx = i+j
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to avoid filesort but not getting luck in removing it from
I would like to increment my global variable tmp_balance_virt in for-each loop but in
I want to increment $x in this function to get next record in table.
I am trying to increment value of float by 0.1 every time. But i
I want increment #hidtr value in jquery. <script type=text/javascript> $('#hidtr').val(parseInt($('#hidtr').val()+1)); alert($('#hidtr').val()); </script>
i want to increment the value in database on each call. ie how to
I am using auto increment value for the inserts in my table. But is
I want to extract rows of group by rls_id but with latest/recent date SELECT
Just can't seem to figure this out, how to prevent the outer loop continuing
I want to increment an integer that gets incremented in a timer event handler

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.