Is there any expression in Swift that similar Python for else syntax
<p>I am solving a algorithm problem, and I use both Python and Swift to solve it. In python, I can use a for else syntax solve it easily. But in Swift, I am struggling to find a way that similar to python's for else syntax. </p>

<p>Here is the algorithm problem, it may help you understand what I am doing.</p>

<blockquote>
  <p>Given a string array words, find the maximum value of length(word[i])
  * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no
  such two words exist, return 0.</p>
  
  <p>Example 1: Given ["abcw", "baz", "foo", "bar", "xtfn", "abcdef"]</p>
  
  <p>Return 16</p>
  
  <p>The two words can be "abcw", "xtfn".</p>
  
  <p>Example 2: Given ["a", "ab", "abc", "d", "cd", "bcd", "abcd"]</p>
  
  <p>Return 4  </p>
  
  <p>The two words can be "ab", "cd".</p>
  
  <p>Example 3: Given ["a", "aa", "aaa", "aaaa"]</p>
  
  <p>Return 0</p>
  
  <p>No such pair of words.</p>
</blockquote>

<p>Here are my two sets code. </p>

<p>The Python code works.</p>

<pre><code>class Solution(object):
    def maxProduct(self, words):

        maximum = 0
        while words:
            currentWord = set(words[0])
            current_length = len(words[0])
            words = words[1:]

            for ele in words:
                for char in currentWord:
                    if char in ele:
                        break
                else:
                    maximum = max(maximum,current_length*len(ele))
        return maximum
</code></pre>

<p>The swift code not works well.</p>

<pre><code>class Solution
{
    func maxProduct(words: [String]) -&gt; Int
    {
        var input = words
        let length = input.count
        var maximum = 0
        while input.count != 0
        {
            let cur_word = Set(input[0].characters)
            let cur_length = input[0].characters.count
            input = Array(input[1..&lt;length])


            for item in input
            {
                for char in item.characters
                {
                    if cur_word.contains(char)
                    {
                        break
                    }
                }

                // how add a control follow here? if cur_word does not share same character with item, then does the below max statement

                //else
                //{
                    maximum = max(maximum,cur_length*(item.characters.count))
                //}


            }

        }
        return maximum
    }
}
</code></pre>

<p>You could just introduce a flag to record if <code>break</code> is called or not. The statement</p>

<pre><code>for a in b:
    if c(a):
        break
else:
    d()
</code></pre>

<p>is the same as</p>

<pre><code>found = False
for a in b:
    if c(a):
        found = True
        break
if not found:
    d()
</code></pre>

<p>But note that you don't need the <code>for char in item.characters</code> loop at all, since you could just use the <a href="https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_SetAlgebraType_Protocol/index.html#//apple_ref/swift/intfm/SetAlgebraType/s:FPs14SetAlgebraType14isDisjointWithFxSb" rel="nofollow"><code>Set.isDisjointWith(_:)</code> method</a>.</p>

<pre><code>if cur_word.isDisjointWith(item.characters) {
    maximum = ...
}
</code></pre>

<p>(On Swift 3 this method is <a href="https://developer.apple.com/reference/swift/set/1781080-isdisjoint" rel="nofollow">renamed to <code>Set.isDisjoint(with:)</code></a>)</p>

python swift2 for-else