Hi all,
can anyone tell me what this statement means, while(false){
do_something();
}
what it means, and where the false condition come from. moreover, how this statement execute in the program.
thanks in advance.
sokoun.
14 14649
Hi all,
can anyone tell me what this statement means, while(false){
do_something();
}
what it means, and where the false condition come from. moreover, how this statement execute in the program.
thanks in advance.
sokoun.
Hi sokoun,tell me what do you think that this piece of code do?
Savage
Hi all,
can anyone tell me what this statement means, while(false){
do_something();
}
what it means, and where the false condition come from. moreover, how this statement execute in the program.
thanks in advance.
sokoun.
hey its just syntax dude..
u have to write condition true/fasle
and the statements to be executed after condn check..
anyway what do u want to do..?
false is a false condition , in C language it means 0 while 1 is true, because c does not include booleans.
suppose you have this code: - #include <stdio.h>
-
#include <stdlib.h>
-
-
main()
-
{
-
int i = 0 ;
-
-
while ( 0 )
-
{
-
if (i ==2 ) break;
-
i ++;
-
}
-
printf("\n%d\n", i);
-
system ("PAUSE");
-
-
}
It will print 0 ... but if you use ' while ( 1 ) ' it will print 2
Hi all,
can anyone tell me what this statement means, while(false){
do_something();
}
what it means, and where the false condition come from. moreover, how this statement execute in the program.
thanks in advance.
sokoun.
Hi sokoun,tell me what do you think that this piece of code do?
Savage
I just wonder about this problem because when i test while(1), i know how it works, but i don't know if while(0) could you tell me?
sokoun.
false is a false condition , in C language it means 0 while 1 is true, because c does not include booleans.
suppose you have this code: - #include <stdio.h>
-
#include <stdlib.h>
-
-
main()
-
{
-
int i = 0 ;
-
-
while ( 0 )
-
{
-
if (i ==2 ) break;
-
i ++;
-
}
-
printf("\n%d\n", i);
-
system ("PAUSE");
-
-
}
It will print 0 ... but if you use ' while ( 1 ) ' it will print 2
thanks for your help
but could you explain me more about this code, because i don't know whether how it works. if while(0) did not affect the program why we use it?
thanks.
I just wonder about this problem because when i test while(1), i know how it works, but i don't know if while(0) could you tell me?
sokoun.
Let's,for e.g:
i=1
while(i)
{
//do something
//if something change i to 0
}
this loop will run until i becomes 0 or with oder words logical false,same with bool,if it is true it will execute a loop else it will not
Savage
Let's,for e.g:
i=1
while(i)
{
//do something
//if something change i to 0
}
this loop will run until i becomes 0 or with oder words logical false,same with bool,if it is true it will execute a loop else it will not
Savage
could you tell me when we use the while(0) for, and when this condition execute.
thanks.
could you tell me when we use the while(0) for, and when this condition execute.
thanks.
while(0) does nothing,it just skips over the loop.It's another way to break,but this time without break keyword.You could do it like: - while(1)
-
{
-
//do something
-
//if something,then break
-
}
the effect would be the same,if you exclude those experts speaking that break keyword is not a good way to get out of a loop and start jumping on your head until you decide to change just while condition and break from loop non-violantly.
Savage
while(0) does nothing,it just skip over the loop.It's another way to break,but this time without break keyword.You could do it like: - while(1)
-
{
-
//do something
-
//if something,then break
-
}
the effect would be the same,if you exclude those experts speaking that break keyword is not a good way to get out of a loop and start jumping on your head until you decide to change just while condition and break from loop non-violantly.
Savage
Maybe break it's not a nice way to exit a loop , but if you use while (1) without break you enter an infinite loop. I've used it just to show a concrete example.
Banfa 9,065
Expert Mod 8TB
could you tell me when we use the while(0) for, and when this condition execute.
If you are asking when you would use while(0) with the 0 hardcoded, as you suggest in each of your posts, rather than using a variable as all the experts are suggesting then the answer is never.
while(0) is a completely pointless statement all it does is prevent the code in the while loop from executing and there are better ways of doing that (deleting it, using preprocessor statements etc). If you have a good optomising compiler then the code in the while loop will not even make it into the binary program, if you don't then you will be wasting space in code memory.
Maybe break it's not a nice way to exit a loop , but if you use while (1) without break you enter an infinite loop. I've used it just to show a concrete example.
That's why you use some variable for while condition.Inside the loop you change the variable to 0 and you are of the loop
Savage
Tha one was just an easy example to show how C language interpretates conditions inside a loop. Some languages use Boolean data type , here it is not necessary. So
0 -> False
1 -> True
Will be the result of your condition.
could you tell me when we use the while(0) for, and when this condition execute.
thanks.
Really ????
Please follow these guidelines when responding to questions.
Provide relevant answers and solutions
That's why you use some variable for while condition.Inside the loop you change the variable to 0 and you are of the loop
Savage
Really ????
Please follow these guidelines when responding to questions.
Provide relevant answers and solutions
??
I already posted such example and double posting is, to say so, a CRIME.
Please refer to post #7.
Savage
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
33 posts
views
Thread by Diez B. Roggisch |
last post: by
|
11 posts
views
Thread by Angus Graham |
last post: by
|
75 posts
views
Thread by Greg McIntyre |
last post: by
|
52 posts
views
Thread by Rick |
last post: by
|
reply
views
Thread by tjonsek |
last post: by
|
40 posts
views
Thread by nufuhsus |
last post: by
| |
12 posts
views
Thread by desktop |
last post: by
|
5 posts
views
Thread by maestro |
last post: by
| | | | | | | | | | |