The best way to handle this is to assemble each logical unit as a partition and create a state diagram for the entire function.
Do not forget that a fall through the beginning of a state is considered a transition and should be considered as such. When you break them down into state transitions, you can start to see where they can be turned into several functions using recursion or iteration, where necessary.
Now I fully admit that I do not understand the function or what it does or should do, but this was the first attempt to draw up a state diagram to give you an idea of what I mean. Pay attention to the cycle at 80
, you probably need a cycle. Note that 10 and 100 are your only return states. Please note that when you go from 30 to 50, there is no turning back. This indicates that 50+ can be its own isolated function, while 10-40 is its own function with a loop, which when it reaches 30 says return functionRepresenting50Pluss(...)
Just note that the filled squares on some state transitions indicate that this transition is guaranteed to be selected if no other transition is made from the state. Note that it does not exist at 80 because I could not really decide if 80 or 90 was a guaranteed destination. Could there be something for 80 cycles forever? Without understanding the function, I can no longer say.
source share