Explain continue statement with example, JAVA Programming

Assignment Help:

Explain continue statement with example?

It is sometimes essential to exit from the middle of a loop. Sometimes you'll need to begin over at the top of the loop. Sometimes you'll need to leave the loop completely. For these reasons Java gives the break and continue statements.

A continue statement returns to the starting of the innermost enclosing loop without completing the rest of the statements in the body of the loop. If you're in a for loop, the counter is incremented. For instance this code fragment skips even parts of an array

for (int i = 0; i < m.length; i++) {
   if (m[i] % 2 == 0) continue;
  // process odd elements...
 }

The continue statement is rarely used in practice, perhaps since most of the examples where it's meaningful have simpler implementations. For example, the above fragment could equally well have been written as

for (int i = 0; i < m.length; i++) {
   if (m[i] % 2 != 0) {
    // process odd elements...
   } 
}

There are just seven uses of continue in the whole Java 1.0.1 source code for the java packages.


Related Discussions:- Explain continue statement with example

Create sudoku in java, The SudCell Class A single cell in a Sudoku ...

The SudCell Class A single cell in a Sudoku must clearly represent a number from 1 to 9 .  But in a solver context, we need much more.  It isn't enough to say "this c

Define about the super() constructer, Super() Constructer: It is used t...

Super() Constructer: It is used to call constructor of parent class. Should be the first statement in the body of constructor. Using this we can access private variables

Advanced java info1414, This is a working program that shows election resul...

This is a working program that shows election results from the infamous 2000 presidential election involving a lot of Floridians and 'hanging chads'. The program as written reads a

OOP, differentiate between states and behaviors of n object

differentiate between states and behaviors of n object

What is the use of lookupdispatchaction, LookupDispatchAction is useful if ...

LookupDispatchAction is useful if the method name in the Action is not driven by its name in the front end, but by the Locale independent key into the resource bundle. As the key i

Java class, java HW should be written with javadoc comment formatted

java HW should be written with javadoc comment formatted

Talent agency system, Talent agencies like ICM, CAA and Paradigm represent ...

Talent agencies like ICM, CAA and Paradigm represent writers, directors and actors (among other talent).  These agencies take in hundreds of millions of dollars a year collecting 1

Name conflicts when importing packages, Name Conflicts when importing packa...

Name Conflicts when importing packages It is possible which you will try to import a package which contains classes in which have the similar name as a class in your own source

COMPRE METHOD, Implement the compare method of the following class Rectangl...

Implement the compare method of the following class RectangleComparator. The method compares two rectangles. The method should return: A positive integer if the area of the first r

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd