Anurag A. Anurag A. - 1 year ago 77
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?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download