Go to Post According to Clarke's third law, I believe their entire robot works by magic. - dtengineering [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-02-2004, 19:40
blindguyinanorg's Avatar
blindguyinanorg blindguyinanorg is offline
Matt Spencer
AKA: Sexy Beast
#1007 (Team Generals)
Team Role: Engineer
 
Join Date: Feb 2004
Location: Snellville GA
Posts: 93
blindguyinanorg has a little shameless behaviour in the past
Send a message via AIM to blindguyinanorg
Boolean statement

simple question, in an if statement is a value of 0 = to false or to i need to say !variable==0 to get false( or variable==1). not too important it will just save me time in writing the code and i dont want to go back and have to fix it.

Last edited by blindguyinanorg : 14-02-2004 at 19:42. Reason: typos
  #2   Spotlight this post!  
Unread 14-02-2004, 20:00
kiracofe8 kiracofe8 is offline
Registered User
#1317 (Digital Fusion)
Team Role: Engineer
 
Join Date: Nov 2001
Location: Columbus, OH
Posts: 30
kiracofe8 will become famous soon enough
Re: Boolean statement

Quote:
Originally Posted by blindguyinanorg
simple question, in an if statement is a value of 0 = to false or to i need to say !variable==0 to get false( or variable==1). not too important it will just save me time in writing the code and i dont want to go back and have to fix it.
int x = 0;
if (x)
//this code never executes
else
//this code always excutes


However, in C, I would consider it to be good coding practice to explicitly write the test as:

if (x == 0)
// stuff
else
// other stuff

or even

if (x != 0)
//other stuff
else
//stuff.
__________________
/* Daniel */
  #3   Spotlight this post!  
Unread 15-02-2004, 07:31
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Boolean statement

Just to clarify what he said, in C any non-zero value is true. Zero is false. So, if you had a variable and you wanted to test if it was zero, you could say:
Code:
    if(!variableBeingTested)
    {
    	// Variable is zero
    }
    else
    {
    	// Variable is not zero
    }
It is considered better form by most people, however to explicitly put in the test for zero. For example:
Code:
     if(variableBeingTested == 0)
     {
     	// Variable is zero
     }
     else
     {
     	// Variable is not zero
     }
--EDIT--
PS I just looked at the last post guy's name and team number and realized he's one of my team's mentors.
__________________


Last edited by Ryan M. : 15-02-2004 at 07:37.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is your most prefered programming language? Hailfire Programming 156 19-01-2005 21:42
Mission Statement Madison FIRST-related Organizations 11 19-05-2003 14:54
Help w/ a Research Paper concerning a Dean Kamen statement Ryan Dognaux Chit-Chat 1 10-02-2003 22:55
Varying levels of enforcement... Gui Cavalcanti General Forum 9 28-03-2002 16:29
Improving PBASIC: Request for Comments Greg Ross Programming 19 16-02-2002 22:14


All times are GMT -5. The time now is 20:13.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi