|
|
|
|
|
by ahci8e
682 days ago
|
|
How would this work if I need to update multiple variables? int value1 = 0;
int value2 = 0;
if (condition) {
value1 = 8;
value2 = 16;
} else {
value1 = 128;
value2 = 256;
}
Would I have to repeat the if expression twice? int value1 = if (condition) { 8 } else { 128 };
int value2 = if (condition) { 16 } else { 256 };
|
|
let (value1, value2) = if (condition) { (8, 16) } else { (16, 256) }
Or else you’d just use some other sort of compound value like a struct or something. Tuple is just convenient for doing it on the fly.