@SlyEcho said:Of course it's overkill, but if you're a programmer, you need to look further ahead and find a more generic solution (you don't always have time for this though). The original problem was finding Excel column names, and Excel 2007 has at least three letter columns (It took some time to scroll that far).Sorry, my mistake. I didn't work with Excel that much and thought ZZ was the last one. Then recursion IS the way to go, just not in the crazy way of the OP.@SlyEcho said:@IMil said:And is changing the value of function input (bonus points for making it in the head of the 'if' operator) considered harmful only by me?
It may seem a little unnatural, but perfectly valid since it's not a reference, only a copy on the stack.It's valid, just confusing. For example, when I enter the debugger, I usually may hover the cursor over the function parameters and see their values. But in your case the initial value would be lost; I'd have step back and examine the caller and that's not always possible.@SlyEcho said:The "improvement" here was to make it not recursive. Lots of people seem to be afraid on stack overflows, but in reality that only happens when your recursions don't terminate properly. The recursive function I wrote originally would only need a maximum of 7 recursions for any positive Int32, for smaller values, even less.Well, that's what I meant by <irony>. A stack overflow is the last thing to worry about with a strictly limited recursion depth. If there's an error that leads to an infinite recursion, the same error in the iterative code would lead to an infinite loop. So I think the recursive version was more readable and thus better (were it correct). I'd even remove the whole StringBuilder thing and just concatenate the strings - for a small number of strings this will be unimportant.