If t2 contains a single integer value that you want to use as the loop boundary, you can use t2.item() to get a python number from the content of the tensor. For loop boundaries, you might need to do int(t2.item()).