for( int componentIndex = 0; componentIndex < 3; ++componentIndex ) { vec.SetByIndex( componentIndex, valueGoesHere );}
Obviously, contrived, but you can scale the operation. I personally do not consider it worthwhile (or indeed, good practice) to build an extension method for this sort of thing though. For complex examples like Spa8nky's, I'd either refactor the complexity to a function (if it's actually that complicated) or pull it outside the loop. The latter can always be done if the computation has no dependence on the component index.