Maybe it helps to shorten the code excerpt a bit:
Code
while(true) {
boolean isAnInt = scanner.hasNextInt();
if(isAnInt) {
int number = scanner.nextInt();
doSomethingWith(number);
} else {
printWarning();
}
scanner.nextLine();
}
scanner.hasNextInt() returns true if the next token can be interpreted as an int (but does not advance past any input).
scanner.nextInt() reads just the number (that you now know exists), not the end of line or anything after the number.
scanner.nextLine() is outside of the if/else statement, gets executed once at the end of the while loop, and reads the remainder of the line.