Change switch to if so that the break statements correctly breaks loop

Docker-DCO-1.1-Signed-off-by: Kohei Tsuruta <coheyxyz@gmail.com> (github: coheyxyz)
Merge pull request #7055 from coheyxyz/break-loop

Break loop correctly