Replace busy wait loops with the wait functionality exposed by kubectl - https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#wait. It supports waiting for deleted resources too.
Alternatively, the command can wait for the given set of resources to be deleted by providing the "delete" keyword as the value to the --for flag.