Anurag A. Anurag A. - 3 months ago 24
Java Question

how do i tell the computer to stop the execution of for loop if certain condition is true within the loop?

public static void main(String[] args)
for (i=1,i>=1,i++)
int A;
Scanner input=new Scanner(;
A= input.nextInt();
if (A==3)

How to Stop the execution of for loop in this case to get a valid output?


You can use break operator without any parameters, or, if you want to skip some iterations you can use continue the same way.

For example:

for (int i = 0; i < 10; i++) {
    if (i > 5 + 1) break;