+ 6
while loop
while(value)? the value in the braces makes the while loop false when the value =0. right?
6 Answers
+ 6
learning is fun
can u please explain what is null
+ 5
can u explain more?
+ 3
In C++ that is a short form for while ( value != 0) because the language treats any value different from 0 (or null) as truth. so you're right
+ 2
you will see later that when you use pointers ( dont worry right now about them , they are used to point to certain places in memory) you can assign then null. null in general is used in programming for when you have an unknown value. for C++ i don't think you have to worry too much about them but in other languages they are used.
+ 1
while ( TEST )
-> If TEST is 0 (NULL) the loop will continues
-> If TEST is any value different from 0 (NULL) the loop will not occur.
The same occur for any test condition like
-> IF (TEST)
-> FOR ( ; TEST ; )
-> DO { ... } WHILE ( TEST );
+ 1
In C and C++ NULL is the same as 0.
But some times developers prefer use NULL than 0 to indicate the variable has no valid value (normally applied to pointers variables when declared).