• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

rewrite some java code


Hi all, below is some java code that ive come across that does'nt look right to me and I want to re - write it. Could someone explain to me whats going on (in the code) and how to re-write it in the java way?

Many thanks

        L1: for (int i = 0; i < var.length; i++)
        {
           if(flag)
            {
               newVar = oldVar;
                break L1;
            }
       }
0
SuAeE
Asked:
SuAeE
1 Solution
 
BradB3030Commented:
well, there is some context missing, can you show us how this fits into a bigger picture?

Feel free to replace SQL queries, usernames, passwords, etc. with *** or phony names if you're worried about posting more.
0
 
SuAeEAuthor Commented:

sure but I dont think it will help you.
The above code is contained in a method like so:

    protected Object processException(Exception e)
    {
      L1: for (int i = 0; i < var.length; i++)
        {
           if(flag)
            {
               newVar = oldVar;
                break L1;
            }
            else
            {
                break L1;
            }
       }
  }

As far as I know L1 is known as a label but how it is used I dont know. L1 is not defined anywhere else in the class.

Thanks
0
 
hoomanvCommented:
> how to re-write it in the java way
it is already in java

the new branching statement in java 1.5 accepts label's as well
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/branch.html
0
 
arun_kuttzCommented:
you dont actually need the label...

 protected Object processException(Exception e)
    {
      for (int i = 0; i < var.length; i++)
        {
           if(flag)
            {
               newVar = oldVar;
                break;
            }
            .....
            ....
       }
  }


the above would work just fine...

-KuTtZ
0
 
Mayank SAssociate Director - Product EngineeringCommented:
BTW, I don't see the exception 'e' being used in that method.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now