# Add elements to tuples or arrays

**URL:** https://discourse.julialang.org/t/add-elements-to-tuples-or-arrays/75885
**Category:** General Usage
**Tags:** arrays
**Created:** [February 6, 2022, 1:02am UTC](https://discourse.julialang.org/t/add-elements-to-tuples-or-arrays/75885 "2022-02-06T01:02:40Z")
**Posts on this page:** 1
**Showing post:** 13

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [February 6, 2022, 3:18pm UTC](https://discourse.julialang.org/t/add-elements-to-tuples-or-arrays/75885/13 "2022-02-06T15:18:58Z")

</div>

I think this is clearly an instance of the [XY problem](https://xyproblem.info/), you are asking for something that you think it is the solution instead of just asking how to solve your real problem. It was not clear (maybe it is not yet, but I think I understand now) what property this function that is not `push!` or `append!` should have to satisfy your requirements.

It seems to me that your problem has nothing to do with `push!` or `append!`, but the fact that the algorithm (or at least the loop inside it) is badly designed. If you wanna grow a `Vector` adding an element for each element **originally** inside it, then just looping over the `Vector` will not work, as you noticed this ends up as an infinite loop. The first solutions I can think of are either:

1. Make a copy of the original `Vector`, iterate over the copy, but make changes to the original, this way the loop will stop where after all the original elements were processed.
2. (Probably the best.) Just save the length of the original `Vector` in a variable, and iterate from 1 to this length, this way the loop will also stop after all the original elements were processed, even if the `Vector` grew in the meantime .

---

_[View the full topic](https://discourse.julialang.org/t/add-elements-to-tuples-or-arrays/75885)._
