What's the difference between a conditionally separated comma and one that uses a double ampersand

I recently came across this type of script using if/let

, and understand what it does, thanks to the post. As I understand it, both conditions must be met before the execution block is executed. Now I ended up seeing it in a regex:

if existingTextHasDecimalSeparator != nil, replacementTextHasDecimalSeparator != nil {
    return false
} else {
    return true
}

      

What's the difference between doing the above and just using &&

it like below ?:

if existingTextHasDecimalSeparator != nil && replacementTextHasDecimalSeparator != nil {
    return false
} else {
    return true
}

      

+3


source to share


2 answers


The comma is used in optional binding with boolean conditions, for example if let a = a, a.isValid()

, while it &&

is a typical operatorAND



+2


source


There seems to be a difference between using &&

conditional numbers for grouping and using commas. I've also seen so far only that it is used with optional chaining, but it seems to work for regex as well, since the following snippet works great.



let bool1 = true;
let bool2 = true;

if bool1 , bool2 {
    print("true");
} else {
    print("false")
}

      

+2


source







All Articles