<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Candara, sans-serif;">
<div>
<div>
<div>Thanks Tim. That makes sense. I don't need it now but your example will be useful if this becomes a bigger issue later.</div>
<div>
<p style="font-size: 12px; margin: 0px; font-family: Verdana;">---</p>
<p style="margin: 0px; font-family: Verdana;"><span style="font-size: 10px;"><b>Timothy Stitt PhD</b> / Head of Scientific Computing</span></p>
<p style="margin: 0px; font-family: Verdana;"><span style="font-size: 10px;">The Genome Analysis Centre (TGAC)</span></p>
<p style="margin: 0px; font-family: Verdana; color: rgb(4, 46, 238);"><span style="text-decoration: underline; font-size: 10px;"><a href="http://www.tgac.ac.uk/">http://www.tgac.ac.uk/</a></span></p>
<p style="margin: 0px; font-family: Cambria; min-height: 19px;"><span style="font-size: 10px;"><br>
</span></p>
<p style="margin: 0px; font-family: Verdana;"><span style="font-size: 10px;">p: +44 1603 450378</span></p>
<p style="margin: 0px; font-family: Verdana; color: rgb(13, 102, 213);"><span style="color: rgb(0, 0, 0); font-size: 10px;">e: <a href="mailto:timothy.stitt@tgac.ac.uk">timothy.stitt@tgac.ac.uk</a></span></p>
</div>
</div>
</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>Tim Armstrong <<a href="mailto:tim.g.armstrong@gmail.com">tim.g.armstrong@gmail.com</a>><br>
<span style="font-weight:bold">Date: </span>Tuesday, 17 March 2015 16:58<br>
<span style="font-weight:bold">To: </span>Timothy Stitt <<a href="mailto:timothy.stitt@tgac.ac.uk">timothy.stitt@tgac.ac.uk</a>><br>
<span style="font-weight:bold">Cc: </span>"<a href="mailto:exm-user@lists.mcs.anl.gov">exm-user@lists.mcs.anl.gov</a>" <<a href="mailto:exm-user@lists.mcs.anl.gov">exm-user@lists.mcs.anl.gov</a>><br>
<span style="font-weight:bold">Subject: </span>Re: [ExM Users] 'break' statement?<br>
</div>
<div><br>
</div>
<div>
<div>
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>There isn't a break statement - it doesn't really fit into the language design since multiple iterations of a loop can be running at the same time.<br>
<br>
</div>
With a foreach loop, you can't prevent iterations from running - they're all independent so there's no concept of a "next" iteration.<br>
<br>
</div>
With the for loop, you can achieve roughly what you're talking about using the loop condition.<br>
<br>
</div>
E.g. a contrived example where we're searching for the first odd number in an array is:<br>
<br>
</div>
<span style="font-family: monospace, monospace;">/*<br>
* Searching for odd numbers<br>
*/<br>
<br>
int A[] = [2, 4, 6, 8, 9, 11];<br>
<br>
for (int i = 0, boolean found = false; i < size(A) && !found; i = i + 1, found = is_odd) {<br>
boolean is_odd = A[i] %% 2 == 1;<br>
<br>
if (is_odd) {<br>
trace(A[i]);<br>
}<br>
}</span><br>
<br>
</div>
This probably looks a little wonky, but with Swift sometimes you have to approach things a little differently to make them work.<br>
<br>
</div>
<div>I'd be a little careful trying to do some of these optimisations - there are some situations where things that work great in other languages can backfire. The trade-off here is that if you just do a regular foreach it can start everything running entirely
in parallel, rather than starting things up one at a time. If you're not sure about something or want some ideas for how to speed up code, I'm more than happy to help.<br>
</div>
<div><br>
</div>
- Tim<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On 17 March 2015 at 11:32, Timothy Stitt (TGAC) <span dir="ltr">
<<a href="mailto:Timothy.Stitt@tgac.ac.uk" target="_blank">Timothy.Stitt@tgac.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Candara,sans-serif">
<div>
<div>
<div>Hi all,</div>
<div><br>
</div>
<div>I was just wondering if there is 'break' statement in Swift 'for' and possibly 'foreach' constructs? </div>
<div><br>
</div>
<div>I have a potential use case that would benefit from this although it probably doesn't take too much overhead right now to go through the entire array looking for a particular item rather than breaking when the item is found.</div>
<div><br>
</div>
<div>Just wondered in case I missed it in the documentation.</div>
<div><br>
</div>
<div>Tim. </div>
<div>
<p style="font-size:12px;margin:0px;font-family:Verdana">---</p>
<p style="margin:0px;font-family:Verdana"><span style="font-size:10px"><b>Timothy Stitt PhD</b> / Head of Scientific Computing</span></p>
<p style="margin:0px;font-family:Verdana"><span style="font-size:10px">The Genome Analysis Centre (TGAC)</span></p>
<p style="margin:0px;font-family:Verdana;color:rgb(4,46,238)"><span style="text-decoration:underline;font-size:10px"><a href="http://www.tgac.ac.uk/" target="_blank">http://www.tgac.ac.uk/</a></span></p>
<p style="margin:0px;font-family:Cambria;min-height:19px"><span style="font-size:10px"><br>
</span></p>
<p style="margin:0px;font-family:Verdana"><span style="font-size:10px">p: <a href="tel:%2B44%201603%20450378" value="+441603450378" target="_blank">
+44 1603 450378</a></span></p>
<p style="margin:0px;font-family:Verdana;color:rgb(13,102,213)"><span style="color:rgb(0,0,0);font-size:10px">e: <a href="mailto:timothy.stitt@tgac.ac.uk" target="_blank">timothy.stitt@tgac.ac.uk</a></span></p>
</div>
</div>
</div>
</div>
<br>
_______________________________________________<br>
ExM-user mailing list<br>
<a href="mailto:ExM-user@lists.mcs.anl.gov">ExM-user@lists.mcs.anl.gov</a><br>
<a href="https://lists.mcs.anl.gov/mailman/listinfo/exm-user" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/exm-user</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</span>
</body>
</html>