# Attempt to access Tuple{Float64, Bool} at index \[0\]

**URL:** <https://discourse.julialang.org/t/attempt-to-access-tuple-float64-bool-at-index-0/74386>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 11, 2022, 10:55am UTC](https://discourse.julialang.org/t/attempt-to-access-tuple-float64-bool-at-index-0/74386 "2022-01-11T10:55:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![frydaydeep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frydaydeep/32/32078_2.png) [@frydaydeep](https://discourse.julialang.org/u/frydaydeep)\
**Post date:** [January 11, 2022, 10:55am UTC](https://discourse.julialang.org/t/attempt-to-access-tuple-float64-bool-at-index-0/74386/1 "2022-01-11T10:55:20Z")

</div>

```julia
a = (1.0,false::Bool)

for i in a
    @show a[i]
end

```

and it returns

> LoadError: BoundsError: attempt to access Tuple{Float64, Bool} at index [0]

however,

```julia
b = (1,2.0)
a[1]
length(a)
    
for i in 1:length(a)
    @show a[i]
end

for i in b
    @show a[i]
end

```

is it because I used different type in a tuple?

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [January 11, 2022, 11:00am UTC](https://discourse.julialang.org/t/attempt-to-access-tuple-float64-bool-at-index-0/74386/2 "2022-01-11T11:00:03Z")

</div>

The syntax `for elt in coll` iterates on the elements of the collection. Therefore, in your example `i` takes in turn the values `1.0` (which, by chance, happens to be a valid index) and `false` (which is seen as `0` and is not a valid index).

TLDR: you can iterate directly on elements in the tuple:

```julia
julia> a = (1.0,false::Bool)
(1.0, false)

julia> for ai in a
           @show ai
       end
ai = 1.0
ai = false

```

Or you can use `eachindex` to iterate on valid indices:

```julia
julia> for i in eachindex(a)
           @show a[i]
       end
a[i] = 1.0
a[i] = false

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 11, 2022, 12:58pm UTC](https://discourse.julialang.org/t/attempt-to-access-tuple-float64-bool-at-index-0/74386/3 "2022-01-11T12:58:24Z")

</div>

Wait, what? Is `1.0` a valid index for tuples? It isn’t for vectors:

```julia
1.7.0> x = [1, 2];

1.7.0> x[1.0]
ERROR: ArgumentError: invalid index: 1.0 of type Float64

```

Why are they different?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 11, 2022, 1:22pm UTC](https://discourse.julialang.org/t/attempt-to-access-tuple-float64-bool-at-index-0/74386/4 "2022-01-11T13:22:24Z")

</div>

My guess is that tuples were overlooked when non-integer indexing of vectors was removed.

```julia
$ ~/julia0.4/bin/julia
               _
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: http://docs.julialang.org
   _ _ _| |_ __ _ | Type "?help" for help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.4.7 (2016-09-18 16:17 UTC)
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-pc-linux-gnu

julia> [1,2][1.0]
WARNING: Indexing with non-Integer Reals is deprecated. It may be that your index arose from an integer division of the form i/j, in which case you should consider using i÷j or div(i,j) instead.
 in depwarn at deprecated.jl:73
 in to_index at deprecated.jl:447
 in getindex at array.jl:283
while loading no file, in expression starting on line 0
1

julia> (1,2)[1.0]
1

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 11, 2022, 2:11pm UTC](https://discourse.julialang.org/t/attempt-to-access-tuple-float64-bool-at-index-0/74386/5 "2022-01-11T14:11:46Z")

</div>

[https://github.com/JuliaLang/julia/pull/43760](https://github.com/JuliaLang/julia/pull/43760)
