# Concerns about this recursive algorithm

**URL:** <https://discourse.julialang.org/t/concerns-about-this-recursive-algorithm/135709>\
**Category:** New to Julia\
**Created:** [February 17, 2026, 4:52pm UTC](https://discourse.julialang.org/t/concerns-about-this-recursive-algorithm/135709 "2026-02-17T16:52:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![i-inferno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/i-inferno/32/218620_2.png) [@i-inferno](https://discourse.julialang.org/u/i-inferno)\
**Post date:** [February 17, 2026, 4:52pm UTC](https://discourse.julialang.org/t/concerns-about-this-recursive-algorithm/135709/1 "2026-02-17T16:52:54Z")

</div>

good morning, afternoon or evening.  
i was working with a for loop today and something seems to have gone very wrong as this is supposed to create a much larger file than it has

```julia-auto
nx = 200
ny = 100
touch("image.PPM")
open("image.PPM", "w") do image  
            write(image,"P3\n" , string(nx) , " " , string(ny) , "\n" , string(255) , "\n")
            for i in ny
                        for j in nx
                                    r = i / ny
                                    g = j / nx
                                    b = 0.2
                                    ir = string(Integer(round(255.99*r)))
                                    write(image, ir , " ")
                                    ig = string(Integer(round(255.99*g)))
                                    write(image,ig , " ")
                                    ib = string(Integer(round(255.99*b)))
                                    write(image,ib , " ")
                                    write(image, "\n")
                                    
                        end
            end
end

```

this should output a ppm file of what is at the start of ray tracing in a weekend but i have not found any results other than a yellow pixel.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [February 17, 2026, 5:00pm UTC](https://discourse.julialang.org/t/concerns-about-this-recursive-algorithm/135709/2 "2026-02-17T17:00:55Z")

</div>

`nx` is a number; `for j in nx` iterates once over that number, since numbers in Julia are iterable. You’re looking for `for j in 1:nx` instead.

See also

> **[Repeated Evaluation: Loops - Control Flow · The Julia Language](https://docs.julialang.org/en/v1/manual/control-flow/#man-loops)**
>
> Julia provides a variety of control flow constructs: | Documentation for The Julia Language.

---

<div class="post-metadata">

**Author:** ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Post date:** [February 17, 2026, 5:35pm UTC](https://discourse.julialang.org/t/concerns-about-this-recursive-algorithm/135709/3 "2026-02-17T17:35:21Z")

</div>

More people looping over integers instead of ranges:

- [https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time](https://discourse.julialang.org/t/i-in-3-is-valid-and-continues-to-cost-me-some-debug-time)
- [https://discourse.julialang.org/t/rant-i-hate-that-its-possible-to-iterate-over-an-integer](https://discourse.julialang.org/t/rant-i-hate-that-its-possible-to-iterate-over-an-integer)
