Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some good answers (especially @Garrett's just now) to a tough question but I'll add my $0.02 for posterity.</p> <p>There is no easy answer here about how to refactor this block without seeing the actual code but my reaction to it is that it needs to be redesigned. </p> <blockquote> <p>For example, a way to call break ; from inside the check() function. (Possibly in other programming languages)</p> </blockquote> <p>If you are asking for a different break that Java does not support (without a hack) and having the duplicated <code>check()</code> and various different loop exit/repeat code indicates to me that this is a large and complicated method. Here are some ideas for you to think about:</p> <ul> <li><p>Each of the <code>some code here</code> blocks are doing something. If you pull those out to their own methods, how does that change the loop?</p></li> <li><p>Maybe break the loop down into a series of comments. Don't get deep into the code but think about it conceptually to see if a different configuration drops out.</p></li> <li><p>Have you had another developer in your organization who is not involved with this code take a look at it? If you explain in detail how the code works someone they may see some patterns that you are not since you are in the weeds.</p></li> </ul> <p>I also think that @aix's idea of a finite state machine is a good one but I've needed to use this sort of mechanism very few times in my programming journeys -- mostly during pattern recognition. I suspect that a redesign of the code with smaller code blocks pulled into methods will be enough to improve the code.</p> <p>If you do want to implement the state machine here are some more details. You could have a loop that was only running a single switch statement that called methods. Each method would return the next value for the switch. This doesn't match your code completely but something like:</p> <pre><code>int state = 0; WHILE: while(true) { switch (state) { case 0: // 1st some code here state = 1; break; case 1: state = check(); break; case 2: return; case 3: break WHILE; case 4: // 2nd some code state = 1; break; ... } } </code></pre> <p>Hope some of this helps and best of luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload