Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 5    Views: 86

Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
03/30/13 10:38 PM (12 years ago)

How to say do nothing in a conditional statement?

I've gotten in the habit of using the following format for conditional statements when I want the first condition to be ignored and the second to be acted on - if(such&such){ Nil; }else{ Do something } Is using "Nil" to represent "do nothing" a safe way to go? I've been searching around and I can't find any references to this. I've been doing it this way for a while and haven't encountered any issues, but I realize there's so many underlying rules with memory management and whatnot...I want to be sure I'm not developing any bad habits
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
03/30/13 10:45 PM (12 years ago)
Your basically just taking the inverse of the if statement. So using the 'not' operator (!) in your if statement would be the way to go. if(!(statement)){ do something }
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/30/13 11:20 PM (12 years ago)
That's exactly what I was looking for..thanks man!
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/31/13 04:07 AM (12 years ago)
if (foo=bar) { // don't do anything. } else { doStuff(); } works, but vlads is prettier :) Cheers! -- Smug
 
Stobe
buzztouch Evangelist
Profile
Posts: 1528
Reg: Mar 04, 2011
Fredericksburg,...
24,680
like
03/31/13 05:12 AM (12 years ago)
I always use the super secret command that not many know about.... if (foo=bar) { U.S. Congress } else { Do something useful } (since "U.S. Congress" = "Do nothing") uh-oh! Is that Buzztouch's first political joke in the forums? We're evolving as a community, lol Disclaimer: No US Congressmen were harmed in the typing of this message
 
Pancho
Code is Art
Profile
Posts: 221
Reg: Mar 06, 2012
Lima
11,610
like
03/31/13 01:35 PM (12 years ago)
:-)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.