Jump to content
  • Advertisement
Sign in to follow this  

loop: for(....) {... continue loop; ....} doesn't work

This topic is 1109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

To demonstrate the problem I have at the moment, consider this simple code. continue loop; discontinues and skips that iteration.

loop: for(int i= 0 ; i < 5; i++){
  continue loop;

will print


For code below, area of interest -:   loop: for ( ... ),  continue. and the print code Log.v(...)

Basically, if  "_rels/.rels" is found that loop should exclude the rest of that iteration and "i" should NOT be 0 at "after" print. But strangely, as the output shows, this didn't happen - the loop did not skip, why?


What code do I add to make sure when the String "_rels/.rels"  is found the iteration jumps to the next?  (not break; as i'm not looking to break out of the loop, I just need to skip that iteration and go to the next).  Many Thanks

      public void unzip() { 
        try  { 
          FileInputStream fin = new FileInputStream(_zipFile); 
          ZipInputStream zin = new ZipInputStream(fin); 
          ZipEntry ze = null; 
          loop:for ( int i=0 ;(ze = zin.getNextEntry()) != null ; i++ ) { 
            Log.v(offset, "Unzipping before continue " + i + "  "+ ze.getName());
            if( ze.getName() == "_rels/.rels" ) continue loop; 

            Log.v(offset, "Unzipping after  continue " + i + "  "+ ze.getName()); 
	            if(ze.isDirectory()) { 
	            } else { 
	              FileOutputStream fout = new FileOutputStream(_location + ze.getName()); 
	              for (int c = zin.read(); c != -1; c = zin.read()) { 
        } catch(Exception e) { 
          Log.e(offset, "unzip", e); 



11-27 04:06:21.073: V/offset(16671): Unzipping before continue 0  _rels/.rels
11-27 04:06:21.073: V/offset(16671): Unzipping after  continue 0  _rels/.rels

Share this post

Link to post
Share on other sites

Seriously, stop hammering the Post button if it doesn't work right away.


This looks like Java. So the problem probably is the string comparison with the literal. Use this:


if ( ze.getName().equals( "_rels/.rels" ) ) continue loop;

Share this post

Link to post
Share on other sites

Many thanks.

I will try that now


(yeah, the site 's been so sticky lately)




Edit:  forgot to update;  if ( ze.getName().equals( "_rels/.rels" ) ) continue loop Work perfectly well

Edited by alwaysGrey

Share this post

Link to post
Share on other sites

Note that using == on Strings may appear to work sometimes, this is very likely due to how Java handles String *literals*, which are often de-duplicated to reduce memory usage. Strings loaded from an external source do not get this behaviour.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!