www.digitalmars.com         C & C++   DMDScript  

D - question: evaluations

reply Lewis <dethbomb hotmail.com> writes:
in vb anything that isnt 0 evaluates to true, is this the same in d?

//example

char[] foo;
foo.length = 1;

if (foo.length) {

}

//or

uint x;
x = -1;
if (x) {  }

//or
while (x) { }


thanks
Jan 14 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Lewis wrote:

 in vb anything that isnt 0 evaluates to true, is this the same in d?

 //example

 char[] foo;
 foo.length = 1;

 if (foo.length) {

 }

 //or

 uint x;
 x = -1;
 if (x) {  }

 //or
 while (x) { }


 thanks
Yes, it's the same in C and C++ as well. One difference is that the literal true = 1 in these languages. In VB the literal true = -1; It's particularly useful for pointers, which are null (0) if they don't have anything in them. int* p; if (p) { //There's something in p }
Jan 14 2004
parent Lewis <dethbomb hotmail.com> writes:
J Anderson wrote:
 Lewis wrote:
 
 in vb anything that isnt 0 evaluates to true, is this the same in d?

 //example

 char[] foo;
 foo.length = 1;

 if (foo.length) {

 }

 //or

 uint x;
 x = -1;
 if (x) {  }

 //or
 while (x) { }


 thanks
Yes, it's the same in C and C++ as well. One difference is that the literal true = 1 in these languages. In VB the literal true = -1; It's particularly useful for pointers, which are null (0) if they don't have anything in them. int* p; if (p) { //There's something in p }
neato! thanks Mr. Anderson
Jan 14 2004