Home > Blockchain >  Recalling a function iteratively
Recalling a function iteratively

Time:11-29

I have a question about recalling my function within a loop.

Below is my code:

List_new = myfunction()
for items in List_new:
    if(my condition is TRUE):
        Execute some commands
    if(my condition is FALSE):
        recall myfunction()

My problem is that I am loading "List_new" using myfunction(). How can I change "List_new" iteratively when my condition is False. I want to reload the function especially when the condition is FALSE. This means I keep calling the function until it is false and then execute the final output from myfunction().

Thank you in advance for your help.

CodePudding user response:

I am going to assume the list generated by myfunction() is a constant size.

You can use a while loop:

List_new = myfunction()
index=0
while index < len(List_new):
    
    items = List_new[index]
    if(my condition is TRUE):
        #Execute some commands
        i =1
    if(my condition is FALSE):
        List_new = myfunction()

Keep in mind that this solution will have an infinite loop if myfunction() continuously generates false values. If you can guarantee that all values will eventually be True then it should always terminate.

  • Related