473,554 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

while(false) { }

sokoun
30 New Member
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.
Sep 6 '07 #1
14 15346
Savage
1,764 Recognized Expert Top Contributor
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
Sep 6 '07 #2
vinvik
16 New Member
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..?
Sep 6 '07 #3
diSangro
69 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. main()
  5. {
  6.       int i = 0 ;
  7.  
  8.       while ( 0 )
  9.       { 
  10.             if (i ==2 ) break;
  11.        i ++;
  12.       }
  13.       printf("\n%d\n", i);
  14.       system ("PAUSE");
  15.  
  16. }


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.
Sep 6 '07 #4
sokoun
30 New Member
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.
Sep 6 '07 #5
sokoun
30 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. main()
  5. {
  6.       int i = 0 ;
  7.  
  8.       while ( 0 )
  9.       { 
  10.             if (i ==2 ) break;
  11.        i ++;
  12.       }
  13.       printf("\n%d\n", i);
  14.       system ("PAUSE");
  15.  
  16. }


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.
Sep 6 '07 #6
Savage
1,764 Recognized Expert Top Contributor
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
Sep 6 '07 #7
sokoun
30 New Member
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.
Sep 6 '07 #8
Savage
1,764 Recognized Expert Top Contributor
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:

Expand|Select|Wrap|Line Numbers
  1. while(1)
  2. {
  3.   //do something
  4.   //if something,then break
  5. }
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
Sep 6 '07 #9
diSangro
69 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. while(1)
  2. {
  3.   //do something
  4.   //if something,then break
  5. }
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.
Sep 6 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

33
3813
by: Diez B. Roggisch | last post by:
Hi, today I rummaged through the language spec to see whats in the for ... else: for me. I was sort of disappointed to learn that the else clauses simply gets executed after the loop-body - regardless of the loop beeing entered or not. So where is an actual use case for that feature? I imagined that the else-clause would only be...
11
4242
by: Angus Graham | last post by:
Hi: I've recently come across a number of programmers who use the following type of do/while(false) structure quite often: do { if (! CatchFish(pFish)) { break; } if (! CleanFish(pFish)) {
75
5298
by: Greg McIntyre | last post by:
I have a Python snippet: f = open("blah.txt", "r") while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit spaghetti.
52
21872
by: Rick | last post by:
Hi, For portability, can an issue arise if we use while(1) for an infinite loop in C? If so, should we then use for(;;)? Thanks, Rick
0
1605
by: tjonsek | last post by:
I am working with directories in PHP for the first time. I have code that I've changed multiple times to try different things. I would think this is pretty standard fare so I'm not sure why I can't seem to get it right. What I would like to see happen: The code opens the directory and loops through the files, opening them and processing...
40
2698
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
3
2491
by: bmerlover | last post by:
I believe my problem lies inside the while loop. When I click the play button on the gui app, it goes inside the while loop, reads the file and calls the necessary function to do what it needs to do. I have it set in a way whenever I click the PLAY button, the PLAY button is suppose to hide and the PAUSE button is suppose to appear. This does not...
12
2557
by: desktop | last post by:
Are there any performance issues between: bool run = true; while(run) { if (bob1 &&){ //dothing break; }
5
1518
by: maestro | last post by:
why does this work? "while p" = "while p != 0" ? 1 is True and 0 is false in python but other numbers have no boolean value so why doesnt it abort. 16 print p p -= 1
0
7605
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7808
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6156
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5441
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5162
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3556
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
845
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.