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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:04:51+00:00 2026-05-14T03:04:51+00:00

I have a written a loop for and if condition and I want to

  • 0

I have a written a loop for and if condition and I want to break to loop completely when if gets satisfied.

while count:
    i=0
    for line in read_record:
        #print str.strip(count[1:28])
        #print str.strip(read_record[i])
        if string.find(str.strip(read_record[i]),str.strip(count[1:28]))>0:
            code=str.strip(read_record[i+19])+str.strip(read_record[i+20])
            print code[25:]
            break

        i=i+1

So here if the if string.find condition gets satisfied I want to go to while loop flow. Please tell me what will be the best place to break and how should I modify the program so that once the if condition is satisfied I am out of the loop and start again with while loop.

  • 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-14T03:04:52+00:00Added an answer on May 14, 2026 at 3:04 am

    Your code already does that. Though it is unclear why do you need nested loops and what are those magic numbers for. Here’s your code refactored a bit for readability:

    while count: # while len(count) > 0 
        for i, record in enumerate(read_record):        
            if count[1:28].strip() in record:
               code= ''.join(map(str.strip, read_record[i+19:i+21]))
               print code[25:]
               break
        else:
            # no break occurred
            pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand how a while loop looks in IL. I have written
I have code such as void myfunc() { introduction(); while(condition()) { complex(); loop(); interior();
I have written the following while loop in a php file. The file does
I have written a simple script that calls a function in a while loop.
Inside MySQL I have written a Procedure where I want to run a loop
I have a loop written like so for( i = (count>=0)?1:-1;(count>=0)?i<=count:i>=count;(count>=0)?i++:i--){ do_something_with( i )
I have written a C# app that runs constantly in a loop and several
I have a game loop written in Haxe/Flash. For some reason it slows down
I have this loop written in C++, that compiled with MSVC2010 takes a long
related (sort of) to this question. I have written a script that will loop

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.