This is a cross language question on coding style.
I have to work with a lot of code that has very long code blocks, sometimes hundreds of lines, inside if statements or for loops. The code is procedural.
Code like the following
if(condition){
//hundreds of lines of code
}else if{
//hundreds of lines of code
} else {
//hundreds of lines of code
}
I have trouble navigating this code if I haven't seen it in a while because I constantly have to scroll back and forth to check which branch of the statement I'm in or whether I'm in a loop, or what the loop iterator is called.
My hunch is to put pieces of the long lines of code inside functions and call them from within the branches of the statements or inside the loops, so the loops and if trees are shorter and therefore more readable. I'd create functions that are sensible code-silos ofcourse, not just cut up the current code haphazardly.
But, and here's my question: is that a good idea? Or is it not a bad coding style to have hundreds of lines of code inside an if statement or a for loop? I'm not a really experienced programmer but I do appreciate clean code :)
Thanks!
Added: The hundreds of lines of code are not repetitive, most of the time. I understand and try to adhere to the DRY principle of course.