View Single Post
  #6   Spotlight this post!  
Unread 02-12-2003, 17:01
josh_johnson josh_johnson is offline
Registered User
#1020 (Indiana Prankmonkeys)
 
Join Date: Nov 2002
Location: Muncie, IN
Posts: 58
josh_johnson is an unknown quantity at this point
Send a message via AIM to josh_johnson Send a message via Yahoo to josh_johnson
Re: Space Limit--What is expendable?

Quote:
Originally Posted by Anthony Kesich
On that note, does anybody know if you can nest the ?: operator? i.e. x=(condtion 1) ? 1 : (condition 2) ? 2 : (condition 3) ? 3 : ... (condition n) ? n : 0
yes, you can nest the ?: operator, although i am not certain of the order of operations so you might want to type it like

x=(condition1 ? 1 : (condition2 ? 2 : (condition3 ? 3 : ...(condition n ? n : 0)...))

also a range of case statements cannot be used as in PBasic however the following is a way to simulate this.


switch(statement) {
case 1:
case 2:
case 3:
doSomething();
break;
case 4:
case 5:
case 6:
doSomethingElse();
break;
}


However this would not be practical for a very large range of values.

Also, if the compiler compiles the sane way as the C compiler I have studied, a switch/case statement uses up more code space than if/else statements, especially when there is a large range of skipped values such as. ..


switch(statement) {
case 1:
doSomething();
break;
case 1000000:
doSomethingElse();
break;
}


Switch/case statements are quicker than several if/else statements though because it jumps to a calculated address rather than having to make many comparisons, but this will not be noticeable if there are only a few choices.
__________________
5! * (4! - 3! - 1!) / 2!

Last edited by josh_johnson : 02-12-2003 at 17:06. Reason: fixed formatting