View Single Post
  #1   Spotlight this post!  
Unread 04-04-2010, 22:30
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Ternary operators

Was I the only one that used these on the robot?

For those not in the know, Ternary operators are essentially an inline if statment.

Example using if statements, like mama told you to do so:
Code:
boolean getState() {
    if(this.thing.state) {
        return true;
    else {
        return false;
    }
}
Example using the ternary operators:
Code:
boolean getStateTernary() {
    return this.thing.state ? true : false;
}
It does the same thing but is way easier.

The layout is:
Code:
variable = [boolean condiditon] ? [if its true] : [if its false];
This works in C, C++, Java, and I believe C#.

Did anyone else use these?