# Understanding Julia

**URL:** <https://discourse.julialang.org/t/understanding-julia/86967>\
**Category:** New to Julia\
**Tags:** python\
**Created:** [September 8, 2022, 11:11pm UTC](https://discourse.julialang.org/t/understanding-julia/86967 "2022-09-08T23:11:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![IssaIssa1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/issaissa1/32/42546_2.png) [@IssaIssa1](https://discourse.julialang.org/u/IssaIssa1)\
**Post date:** [September 8, 2022, 11:11pm UTC](https://discourse.julialang.org/t/understanding-julia/86967/1 "2022-09-08T23:11:01Z")

</div>

Hello,  
I am new to julia. I am trying to understand the logic behind the following code. I know that && is a logical and but what excatly does it mean in this case? I appreciate your help.

```julia
for i = 1:len(d)
    set = sets
    lb = foo(x,y)
    lb > best_cost && continue

    for v in set
        #do something
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [September 8, 2022, 11:18pm UTC](https://discourse.julialang.org/t/understanding-julia/86967/2 "2022-09-08T23:18:16Z")

</div>

This is called short-circuit evaluation for control flow (explained [here in the manual](https://docs.julialang.org/en/v1/manual/control-flow/#Short-Circuit-Evaluation)).

In short when you use `&&` (reads “and”) the thing in the right side of the operator is evaluated **only** if the thing in the left evaluates to true (if the thing in the right is not true then it does not make sense to compute it).

So people use it to control the flow of a program. That part is equivalent to:

```julia
if lb > best_cost
   continue
end
for v in set
    #do something 
end

end

```

If `lb > best_cost` the thing loop continues to the next iteration without computing the inner for loop.

---

<div class="post-metadata">

**Author:** ![IssaIssa1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/issaissa1/32/42546_2.png) [@IssaIssa1](https://discourse.julialang.org/u/IssaIssa1)\
**Post date:** [September 8, 2022, 11:23pm UTC](https://discourse.julialang.org/t/understanding-julia/86967/3 "2022-09-08T23:23:15Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![IssaIssa1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/issaissa1/32/42546_2.png) [@IssaIssa1](https://discourse.julialang.org/u/IssaIssa1)\
**Post date:** [September 8, 2022, 11:50pm UTC](https://discourse.julialang.org/t/understanding-julia/86967/4 "2022-09-08T23:50:04Z")

</div>

How would you read || in case it was in place of &&?

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [September 9, 2022, 12:05am UTC](https://discourse.julialang.org/t/understanding-julia/86967/5 "2022-09-09T00:05:54Z")

</div>

Find out by trying it in the REPL!

```julia
julia> true || "hello"
?

julia> false || "hello"
?

```

When used for control flow in this way, you can read `&&` as “and if so, then” and `||` as “or else”.
