Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeat an iteration in loop if error occurs

Tags:

People also ask

How do I continue a loop if error in R?

One of the easier ways is to ignore them and continue moving through the loop. This is accomplished with the try function which simply wraps around the entire body of the loop. By default, try will continue the loop even if there's an error, but will still show the error message.

How do you repeat a loop for a certain number?

You can do the same type of for loop if you want to loop over every character in a string. To loop through a set of code a certain number of times, you can use the range() function, which returns a list of numbers starting from 0 to the specified end number.

Does a for loop repeat?

A "For" Loop is used to repeat a specific block of code a known number of times.


Is there a command such as break and continue which could repeat recent iteration?

For example, when exception is thrown.

for i in range(0,500):
    try:
        conn = getConnection(url+str(i))
        doSomething(conn)
    except:
        repeat

Let's have an iteration where i variable's value is 6. During this iteration some connection error occurred. I want to repeat this iteration.

Is there a command which can do that?

Of course I can do this:

i=0
while i!=500:
    try:
        conn = getConnection(url+str(i))
        doSomething(conn)
        i+=1
    except:
        pass