Search code examples
c#.netif-statementforeachgoto

Nested for-each and if-else statement without goto statement


I have a nested for-each and if-else cases like below. In these scenario if the if-else based on the if-else statement I have to go to the starting of the loop or somewhere else in the loop. Is GOTO is the only way to work with this kind of scenarios? or it can be better design? for brevity I have included only two for-each but in my case I have 4 for-each and around 13 if-else statement.

enter image description here


Solution

  • If your method is that long, it is a bad smell. Break it into smaller methods or smaller classes. That will makes it also easier to jump to an other position.

    Maybe state machine principles will help you to set the next status.