   Best method to shorten the usages of IF conditions: How?
  Here's the code:bool Must_Return_Value(){   long int* pointer1 = &Number1;   long int* pointer2 = &Number2;   //...   long int* pointerN = &NumberN;   if (pointer1 != NULL)  return false;   if (pointer2 != NULL)  return false;   //...   if (pointerN != NULL)  return false;}We know at first, there are N number of pointers declared in the function. So, we have to have N number of IF conditions to check the pointers if any one of them is NULL or not.Assuming that the variables Number, labeled from 1 to N, if it doesn't contain any value, the corresponding pointer, labeled 1 to N, will be NULL. If any one of the pointers return True, the whole function returns False.Is there a better method of shortening all those IF conditions to check whether if any one pointer returns a NULL?Thanks in advance. Hope it's not too vague.   
  Use a for loop and arrays?long int *pointers[N];for(int i=0; i < N; i++){if(pointers == NULL){return false;}};  In many cases, if your code has some name-pattern <foo>_N or similar, then loops and arrays are the better solution. But if loops and arrays (or better alternatives to them, of course) are no option, than you can use the logical-or operator, which yields the exact same behaviour as your code (i.e. it does evaluate in a short circuit):if (foo != NULL || bar != NULL || frob != NULL) {   return false;    };  Yes, those pointers aren't labeled with numbers at the end.Is it possible to use switch-case inside IF conditions? I'm not at a computer with VS C++ installed.;Quote:Original post by tom_mai78101Is it possible to use switch-case inside IF conditions? I'm not at a computer with VS C++ installed.Of course. You can nest statements as deep as you want:if (true) {    switch(0) {    case 0:   if (0 == 1) {} else switch (1) {default:break;}   break;    }}Valid, though not very meaningful code.   ;  Thanks!   ;  While you are thinking of reducing the use of `if': ">[Edited by - alvaro on May 17, 2010 11:25:11 AM];  If you just need to check if any of the pointers equals non-NULL, you could do thislong res = (long)pointer1 | (long)pointer2 | (long)pointer3;if (res == (long)NULL) printf("All pointers NULL");Though, I'd advise to keep the IF statements unless there's a HUGE amount of them.   ;  That's the main problem: I have too many NULL-checking pointers.   ;Quote:bool Must_Return_Value(){   long int* pointer1 = &Number1   if (pointer1 != NULL)  return false;}In this specific case there's no need for the null test at all. The address of any variable will be non-null (unless operator& has been overloaded, or it's the first member variable and this is null). I'd expect a good compiler to optimize that test away in release builds.   