Created
February 25, 2023 03:39
-
-
Save anqit/cab11271c6d481729b457e5a1585aa88 to your computer and use it in GitHub Desktop.
Boolean compound assignment operators should short-circuit if possible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool longComp() { | |
print('doing long computation'); | |
return true; | |
} | |
void main() { | |
var t = true; | |
var f = false; | |
t |= longComp(); // prints 'doing long computation' | |
f &= longComp(); // prints 'doing long computation' | |
t = t || longComp(); // short-circuits, nothing is printed | |
f = f && longComp(); // short-circuits, nothing is printed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment