Exercise 2: the while true loop

Hello
why is the while True loop required here? because of that I think my code is going into infinite loop,

I’m not an NLP mentor and don’t know that assignment, but infinite loops are a Bad Thing ™. There must be some logic in the loop that does a “break” under the right conditions. If not, then you need to consider where and how to add such logic. :nerd_face: If they don’t give you any hints in the template code, then part of the point is that you need to figure that out. The instructions in the assignments are usually pretty complete. If you missed that on the first time through, it might be worth another careful reading of the instructions.

1 Like
### START CODE HERE ###
while True:



    # if the current batch is now equal to the desired batch size



        ### END CODE HERE ##
        
        # Yield two copies of the batch and mask.
        yield batch_np_arr, batch_np_arr, mask_np_arr`

Note the use of the yield expression. Yield is similar to a return. The differences are probably beyond the scope of this discussion. It isn’t an infinite loop unless the if statement is never evaluating to True which could happen if the current batch is not being constructed properly so its length never reaches the threshold batch size. HTH

ps: I took this class a year ago so details might have changed, but it’s at least worth taking a look.

1 Like

That worked! Thankyou!

1 Like