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

Mine craft plug-in coder, Mine craft plug-in Coder Project Description: ...

Mine craft plug-in Coder Project Description: Some custom plugging for my Mine craft server. Skills required: Java, Editing

Concept of events and events listeners and events handlers, Question: (...

Question: (a) State and explain clearly FIVE new features of Actionscript 3.0 as compared to Actionscript 2.0. (b) Explain clearly the concept of events and events listen

How does java allocate heap and stack memory?, Each time an object is start...

Each time an object is started in Java it goes into the area of memory named as heap. The primitive variables like double and int are allocated in the stack, if they are local inst

Array method, frequently used java array method

frequently used java array method

What is javaserver faces conversion model, A mechanism for converting among...

A mechanism for converting among string-based markup generated by JavaServer Faces UI components and server-side Java objects.

Develop a color picker, Project Description: We need same kind of concep...

Project Description: We need same kind of concept with some changes # Change single colors in a particular design. you need to be able to change the color of only the fox or

Translate four row solitaires from java swing to android, Translate Four Ro...

Translate Four Row Solitaires from Java Swing to Android. Project Description: There is a product known Four Row Solitaire listed in GitHub. I would like Swing GUI to be repl

Program that can read the obj file - wireframe model, We need an OpenGL - b...

We need an OpenGL - based visualisation of an OBJ-File that was created out of Maya3D. (important: we have to use OpenGL with Java - JOGL) In other words: we have an OBJ-file (a

Explain the 4 phases of RUP?, 1. Inception : In the mean while the inc...

1. Inception : In the mean while the inception phase, you work out the business part for the project. You also will be creating a rough cost estimate and return on investment.

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