• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

about Continue pls explain me

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class MyFor{

public static void main(String argv[]){
int i;int j;

outer:

for (i=1;i <3;i++)

inner:for(j=1; j<3; j++)
{ if (j==2)
continue outer;
System.out.println("Value for i=" + i + " Value for j=" +j);} }}
output is
Value for i=1 Value for j=1
Value for i=2 Value for j=1


can anyone explain me this set of code..and how the output is ..im struggling only this type of question please help me
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what's called a "labelled continue statement". Since the continue keyword is followed by a label, control goes to the outer loop. The outer loop is continued by first incrementing the variable i, testing the condition i < 3. The outer loop continues as the next iteration. Then the inner loop is started over again with j = 1 just because that's what's next in the control flow.

The inner label is never used and has no effect.

The labeled continue in this case is supposedly useful because there are two loops that are nested and the labeled continue allows you to get out of the inner loop and continue the outer loop.

Does that answer your question?

Kaydell
 
The moustache of a titan! The ad of a flea:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic