The first time you want to go to the repeat using continue in a multiple repeat statement,

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

Hello, everyone There are several repetitive statements, and I want to start with the first repetitive statements under certain conditions, what should I do? I don't know what to do

# Omit the above code
while True:
    # Where do you want to go back?
    # omit the while code

    for i, ad in zip(df, adsl):
        logger.debug('i.drop(0, axis=0, inplace=True)')
        ni = i.drop(0, axis=0)
        ni = ni.drop(0, axis=1)

        if ni.empty:
            logger.info (no NOTAM in f'{ad})
            dins[ad]
        else:
            for idx, row in ni.iterrows():
                if pd.isna(row).any() != True:
                    row.dropna(inplace=True, axis=0)
                    logger.debug("row.str.extract(r'(.*)').iloc[0].iloc[0]")
                    notam = row.str.extract(r'(.*)').iloc[0].iloc[0]
                    notam_nbr = notam[:8] # NotamNumber
                    notam_content = notam[11:] # RohTamBorn
                    dins[ad][notam_nbr] = notam_content
                else:
                    logger.info ('Return to First Time').')
                    Continue ##### I want to go back to the beginning of the half-text here

python loops continue

2022-09-20 15:41

1 Answers

while True:
    condition=False

    for i in range(10):

        for j in range(10):

            if j==5:
                condition=True
                break

        if condition==True:
            break

Like the code above, change the condition of a particular variable (for example, j==5) to True, break one inner loop, and if the condition is true immediately after exiting the inner loop, write the code to exit the loop again.

In the question, I asked you through continue, but if you write a code using continue instead of break, the code will get messier, so it would be better to use break.

# Omit the above code
while True:
    condition=False
    # Where do you want to go back?
    # omit the while code

    for i, ad in zip(df, adsl):
        logger.debug('i.drop(0, axis=0, inplace=True)')
        ni = i.drop(0, axis=0)
        ni = ni.drop(0, axis=1)

        if ni.empty:
            logger.info (no NOTAM in f'{ad})
            dins[ad]
        else:
            for idx, row in ni.iterrows():
                if pd.isna(row).any() != True:
                    row.dropna(inplace=True, axis=0)
                    logger.debug("row.str.extract(r'(.*)').iloc[0].iloc[0]")
                    notam = row.str.extract(r'(.*)').iloc[0].iloc[0]
                    notam_nbr = notam[:8] # NotamNumber
                    notam_content = notam[11:] # RohTamBorn
                    dins[ad][notam_nbr] = notam_content
                else:
                    logger.info ('Return to First Time').')
                    #continue #### I want to go back to the beginning of the half-text here while
                    condition=True
                    break
            if condition==True:
                break


2022-09-20 15:41

If you have any answers or tips


© 2022 pinfo. All rights reserved.