while loop | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 6

while loop

while(value)? the value in the braces makes the while loop false when the value =0. right?

17th Nov 2016, 7:15 PM
F.Heeh. 2nd Yr. Hebron UniversityÔÇĆÔÇÄ
F.Heeh. 2nd Yr. Hebron UniversityÔÇĆÔÇÄ - avatar
6 Antworten
+ 6
learning is fun can u please explain what is null
17th Nov 2016, 8:56 PM
F.Heeh. 2nd Yr. Hebron UniversityÔÇĆÔÇÄ
F.Heeh. 2nd Yr. Hebron UniversityÔÇĆÔÇÄ - avatar
+ 5
can u explain more?
18th Nov 2016, 8:42 AM
F.Heeh. 2nd Yr. Hebron UniversityÔÇĆÔÇÄ
F.Heeh. 2nd Yr. Hebron UniversityÔÇĆÔÇÄ - avatar
+ 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
17th Nov 2016, 7:33 PM
Learning is fun
+ 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.
18th Nov 2016, 3:57 AM
Learning is fun
+ 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 );
17th Nov 2016, 9:10 PM
Henrique Zenoni Machado
Henrique Zenoni Machado - avatar
+ 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).
18th Nov 2016, 5:49 AM
Henrique Zenoni Machado
Henrique Zenoni Machado - avatar