You don’t need to do anything to exit the if
statement. As Anonymous already mentioned in a comment.
I added the variable declarations that are not in the code that you posted in the question and ran your code. A sample session:
1
How many?
2
1
How many?
1
4
Total laptops: 3
As you can see, I also added a statement after the loop to print the result:
System.out.println("Total laptops: " + laptops);
So your code already works fine.
Your if
statement ends at the right curly brace }
. And since you have no statements after the if
statement (before the curly brace that ends the loop), it then goes back to the top of the loop.