# For loop untill condition == True - Brute Force

**URL:** <https://discourse.julialang.org/t/for-loop-untill-condition-true-brute-force/58583>\
**Category:** General Usage\
**Created:** [April 5, 2021, 12:13am UTC](https://discourse.julialang.org/t/for-loop-untill-condition-true-brute-force/58583 "2021-04-05T00:13:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![statspy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/statspy/32/26630_2.png) [@statspy](https://discourse.julialang.org/u/statspy)\
**Post date:** [April 5, 2021, 12:13am UTC](https://discourse.julialang.org/t/for-loop-untill-condition-true-brute-force/58583/1 "2021-04-05T00:13:43Z")

</div>

I am trying to solve a diophantine equation using a simple for loop to solve this equation:  
`f(x,y) = x^2 + y^3 == 31`  
So i have defined:  
`X = collect(1:1:10)` e `Y= collect(1:1:10)`  
and tried:

```julia
for i in Y
    for j in X
          println(i, j, f(i,j))
    end
end

```

There a True return(2,3) and I want to get the X and Y of this True return and not all the false results…but I am not able to do it so far…any tips?

How can i code this?

---

<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:** [April 5, 2021, 1:24am UTC](https://discourse.julialang.org/t/for-loop-untill-condition-true-brute-force/58583/2 "2021-04-05T01:24:50Z")

</div>

```julia
function solve_equation(f::Function, X, Y)
    for x in X
        for y in Y
            if f(x,y)
                return (x, y)
            end
         end
    end
    println("No solutions found")
end
solve_equation(f, 1:10, 1:10)

```

Does this do what you want?

---

<div class="post-metadata">

**Author:** ![statspy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/statspy/32/26630_2.png) [@statspy](https://discourse.julialang.org/u/statspy)\
**Post date:** [April 5, 2021, 1:27am UTC](https://discourse.julialang.org/t/for-loop-untill-condition-true-brute-force/58583/3 "2021-04-05T01:27:31Z")

</div>

> [@Oscar\_Smith](#):
>
> ```julia
> function solve_equation(f::Function, X, Y)
> for x in X
> for y in Y
> if f(x,y)
> return (x, y)
> end
> end
> end
> println("No solutions found")
> end
> solve_equation(f, 1:10, 1:10)
> 
> ```

yes. Thanks man.
