Skip to content

By Programmer For Programmer

Here I lay down the useful tips, tricks and utilities for programmers like myself.

Archive

Category: Uncategorized

Just wanted to give props real quick to the awesome profiler JProfiler (http://www.ej-technologies.com/products/jprofiler/overview.html) for providing me with an open-source license to profile my open-source project HTML4Java (https://sourceforge.net/projects/html4java/). The open-source community is so friendly :) .

Ever wanted to continue from a doubly-nested for loop? How about break from a switch statement more than one level deep?

Simple! First you have to label your loop, and then put that label name after the break or continue keyword.

“continue” example:

fooloop: for(foo: foos) {
    ...
    barloop: for(bar : bars) {
        ...
        for (blotto : blottos) {
            ...
            if (next_innermost_loop)
                continue; //normal
            if (next_middle_loop)
                continue barloop; //goes to the next iteration of "barloop"
            if (next_outer_loop)
                continue fooloop; //goes to the next iteration of the outermost loop, "fooloop"
        }
    }
}

“break” example:

fooswitch: switch(foo) {
    case 1:
        ...
        break;
    case 2:
        ...
       switch(bar) {
            ...
            if (break_this_switch)
                break; //normal
            if (break_outer_switch)
                break fooswitch; // breaks out of the out switch, "fooswitch"
        }
}

While most might consider this bad practice, when writing some scratch code to do some one-off task that only you will ever use, sometimes it’s nice to use a shortcut :) .

I was getting the annoying error in Eclipse with Tomcat where it didn’t think it could publish an application since some files were locked, when they were locked by the javaw.exe process that eclipse.exe started. The fix for me was to not have “Use Tomcat installation” selected in my server configuration. When I switched back to the default of “Use workspace metadata”, the error stopped happening.