Computer Science, asked by Pikachu82, 1 year ago

when For loop will terminated in java ?

Answers

Answered by orangesquirrel
13

In the Java Programming language, when the break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. It is also used to exit a loop.There are two types of break statement in java programming language. They are as follows:

Unlabelled and labelled.

Answered by Arslankincsem
4

In Java, the loop body cannot be executed if the termination expression is false. But if the termination expression evaluates to false then it then the loop in Java will be terminated. Here you can find an example of loop in Java:  

/**

* This class provides some example for-loops.

*  

* @author Woolbright

* @version 2008

*/

public class ForRunner

{

 public static void main(String[] args)

 {

     /*

      * A typical loop

      */

     for(int i = 0; i < 10; i++)

     {

         System.out.println(i);

     }

     /*

      * A loop with multiple initialization statements

      */

     int x;

     int y;

     for(x = 3,y = 4; x + y < 15; x++,y++)

     {

         System.out.println("x: " + x + " y: " + y);

     }

     /*

      * Possibly infinite loop

      */

     int z = 0;

     for( ; ; )  

     {

         z++;

         if (z > 10) break;

         System.out.println(z);

     }

 }

}

Similar questions