Friday, November 17, 2017

Continue Statement in Java with Example

Continue statement is for the most part utilized inside circles. At whatever point it is experienced inside a circle, control specifically bounces to the start of the circle for next cycle, skirting the execution of articulations inside circle's body for the present emphasis. This is especially helpful when you need to proceed with the circle, however, don't need whatever is left of the statements(after proceeding with proclamation) in circle body to execute for that specific emphasis.

Continue Statement In Java With Example

Example:

public class my
{

      
public static void main(String args[])
      {
             for (int j=0; j<=6; j++)
            {
                  if (j==4)
                 {
                    continue;
                 }
                  System.out.print(j+" ");
             }
       }

}

Output:
1
2
3
5
6

  • Use of Continuing in While Loop

public class demo
{

        public static void main(String args[])
       {
              int counter=10;
              while (counter >=0)
              {
                  if (counter==7)
                      { 
                          counter--;
                          continue;
                      }
                         System.out.print(counter+" ");
                         counter--;
               }
        }
}

Output:
10
9
8
6
5
4
3
2
1

  • Continue the Do-While Loop

public class test

 {
        public static void main(String args[])
       {
                int j=0;
                do
               {
                       if (j==7)
                      {
                         j++;
                        continue;
                      }
                        System.out.print(j+ " ");
                        j++;
                }
                       while(j<10);
         }
}

Output:
0
1
2
3
4
5
6
8
9

No comments:

Post a Comment

Top 200+ Core Java Interview Questions And Answers For 2019

Most Popular Java Interview Questions Given below is a comprehensive list of most important and commonly asked basic and advanced Java p...