Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested for loop syntax & break behavior #5154

Closed
quinnj opened this issue Dec 15, 2013 · 2 comments
Closed

Nested for loop syntax & break behavior #5154

quinnj opened this issue Dec 15, 2013 · 2 comments
Labels
kind:breaking This change will break code needs decision A decision on this change is needed

Comments

@quinnj
Copy link
Member

quinnj commented Dec 15, 2013

I noticed this today

In  [8]: for a = 1:3, b = 4:6
    b == 5 && break
    println("a = $a")
    println("b = $b")
end

a = 1
b = 4
a = 2
b = 4
a = 3
b = 4

(i.e. the break only breaks the inner loop).
I'm not saying this is wrong, but it might be good to add a sentence or two about it in the docs as one might think that the nested loop syntax only creates a single loop to break from.

@JeffBezanson
Copy link
Sponsor Member

And then there's always #330.
I always thought of this form as just a syntactic convenience, but maybe we are "wasting syntax" by not having this kind of loop mean something different --- namely that you want conceptually a "single" loop but over an n-d space.

@StefanKarpinski
Copy link
Sponsor Member

I'm rather in favor of that. It makes it a little easier to express a different behavior and the bonus is that I think the difference is not only useful but entirely intuitive. Imagining writing that paragraph in the manual doesn't make me wince.

@nolta nolta closed this as completed in 91cdce7 Jul 3, 2014
JeffBezanson added a commit that referenced this issue Jul 3, 2014
fix #5154 (nested for loop syntax & break behavior)
GaZ3ll3 referenced this issue in JuliaCN/julia_zh_cn Jul 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:breaking This change will break code needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

3 participants