Steve wrote:
> newval = (myval == someval) ? somefunction : otherfunction;
> Expands out to...
> if(myval == someval)
> {
> newval = somefunction;
> }else{
> newval = otherfunction;
> }
No, it expands out to
if (myval == someval) {
newval = somefunction;
} else {
newval = otherfunction;
}
> That works great on it's own, but if I'm trying to do it as part of
> another larger statement it makes the whole statement overall less
> clear.
The statement in question, however, is a separate beast.
letter = (counter == 0) ? toupper(letter) : letter;
is better expressed as
if (!counter) letter = toupper(letter);
Even the first double-length line is better expressed as a ternary
inside an if, to avoid the same kind of assignment to self, and to avoid
confusing the reader with nested ternary operators:
if (letter == oldletter) {
letter = (coin <= 60)? PickChar(vowels): PickChar(consonants);
}
What I find most odd, though, is that you never pick a new character
first, so this conditional is always true after the first iteration.
- Eric
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/