View Single Post
  #9   Spotlight this post!  
Unread 06-04-2004, 20:52
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Do you use ternary operators in your code?

Quote:
Originally Posted by JJG13
I try to do whatever is most readable but instead of
Code:
if (y > 5)
  x = 1;
else
  x = 0;
I would use
Code:
x = (y > 5);
yes, just remember that not all compilers treat logical TRUE as 1. it's fine to use it as long as you know it works. more robust, however, is the ternary:
Code:
x = y > 5 ? 1 : 0;
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)