System.exit(0) terminates your program whether u are in a loop or not.