Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3695710
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:39:03+00:00 2026-05-19T04:39:03+00:00

I am generating Java code on the fly which will then be compiled and

  • 0

I am generating Java code on the fly which will then be compiled and loaded back in. My issues is that I essentially need jumps because when I return from the function I wish to continue execution from the point in the loop from where I have exited. Hopefully, the code here illustrates my desire. Although the actual code will have some ifs as well and be much deeper.

MyIter a,b,c;

boolean func() {
 jump to correct state here

 state0:

 a = ...;
 while (a.next()) {
   state1: while (b.next()) {
     return true; // start again at state1
   }
   b = ...;
 }

 c = ...;
 state2:
 while (c.next()) {
   return true; // start again at state2
 }
 return false;
}

In C I would probably use a jump table and state variable. Performance is the key here and the code interacts with the Java application.

My best guesses so far have been:

  • Flipping the nesting of loops and the logic. That became too cumbersome and problematic.
  • Adding logic to allow the flow to get back to where it was but this may be messy.
  • I assume the bytecode can jump so I could generate the bytecode myself but that doesn’t seem ideal (is there any good libraries for this?)
  • Continuation passing style to avoid returning but that would involve major restructuring, although currently the likely way to go.

I was wondering if anyone had any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:39:03+00:00Added an answer on May 19, 2026 at 4:39 am

    The simplest option is to use a switch block (or if you have to, nested switch statements)

    enum State {
       state1, state2, state3;
    }
    
    State state = State.state1;
    
    public boolean func() {
       while(true) {
         switch(state) {
            case state1:
                if(test()) return true;
                state = state2;
                break;
            case state2:
                if(test2()) return false;
                state = state3;
                break;
            case state3:
                if(test3()) return true;
                state = state1;
                break;
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following Java code for generating a binary file: DataOutputStream out = new
I'm looking at the possibility of generating Java byte code at run time (hopefully
We have a need to generate Java source code. We do this by modeling
I am generating JavaScript pages through Java code like: FileOutputStream fs=new FileOutputStream(C:\\Documents and Settings\\prajakta\\Desktop\\searcheng.html);
Any tool for automatically generating unit tests for Java code? UPDATE: Primary intended use
I'm looking for Java code that can be used to generate sound at runtime
What is the best, preferably free/open source tool for auto-generating Java unit-tests? I know,
I'm well aware of Java tools for manipulating, generating, decompiling JVM bytecode (ASM, cglib,
I'm generating some xml files that needs to conform to an xsd file that
It seems to me that, in some ways, Java is where C was a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.