Hi and welcome to the forum 
It should work, as the train loader is agnostic to the way you loop (while or for). The essential part is that you call for (images, labels) in trainloader, the fact that it’s called inside a while or for loop is not important.
You can verify that it does shuffle it by printing, for example, the labels at each iteration:
while i <= cfg["training"]["train_iters"] and flag:
    for j, (images, labels) in enumerate(trainloader):
        if j == 0:
            print(labels)
            break

(Note that this will be an infinite loop by itself, since i is not modified).