View Single Post
  #7   Spotlight this post!  
Unread 29-01-2004, 11:32
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: help! Am really stuck!!!!

Quote:
Originally Posted by Mark McLeod
...and there should be no colon (or semicolon) after "254". It really should be:

Code:
if (rc_dig_in06 == 0) 
  pwm01=254
else 
  pwm01=127;

or if you really like to run things together:

if (rc_dig_in06 == 0) pwm01=254 else pwm01=127;
umm... no. There should be a semicolon after the 254 - it is the end of an instruction. the correct format is this:

Code:
if(rc_dig_in06 == 0)
    pwm01 = 254;
else
    pwm01=127;
(you can always rearrange that however you wish with tabs, spaces, and line breaks)

Remember, the if-else statement is a control structure, and thus does not count as part of a single instruction. The two instructions here are "pwm01 = 254" and "pwm01 = 127", each of which needs to be ended with a semicolon as shown.

You may have been confused with the colon because of the if-else shorthand notation - for instance, the code below does the exact same thing as the longer if-else below:

Code:
pwm01 = ( rc_dig_in06 ? 127 : 254 );
if you are new to programming, though, stick with the longer if-else statement, as it is easier to read and use.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)

Last edited by deltacoder1020 : 29-01-2004 at 11:36.