473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

clear for loop doubt

rampraveen
for(;;)....what is the meaning for this loop...please tell....
May 18 '10 #1
7 1499
Markus
6,050 Expert 4TB
Well, it's a for loop without any initialisation code, condition, nor post-loop action. It's an infinite loop.
May 18 '10 #2
RedSon
5,000 Expert 4TB
It is equal to:

"while (true)"
May 18 '10 #3
whodgson
542 512MB
No, because 'true' is a condition which must continue to be fulfilled for the loop to continue. Whereas with for(;;) some other statement in the body of the loop is required to stop it
May 19 '10 #4
jkmyoung
2,057 Expert 2GB
Thought of posting that too, but in the pseudocode sense (probably what the OP wants), it is the same.

If the compiler can optimize the instruction, it is the same. If not, it's an extra line of assembly.
May 19 '10 #5
RedSon
5,000 Expert 4TB
@whodgson
If you use the literal boolean true, the loop's condition will remain true forever. I don't see how there is a difference between while (true) and for(;;). You can't change the condition of the loop in the loop's code. You can only get out of the while(true) loop by having a break or goto or something like that.

Unless you are comparing while(true) to something like for(;true;). Which I guess is syntactically a bit closer but conceptually the same as for(;;).
May 19 '10 #6
jkmyoung
2,057 Expert 2GB
Assembly pseudo
Expand|Select|Wrap|Line Numbers
  1. a: and b: represent addresses in assembly and are not actually instructions.
  2.  
  3. for(;;):
  4. a: // start of loop address, first line inside for loop code
  5. ...rest of code
  6. goto a
  7. b: continuation of code.
  8.  
  9. while(true):
  10. a: if 0 neq 0 goto b
  11. first line of code
  12. rest of code
  13. goto a
  14. b: continuation of code.
  15.  
  16. OR (depending on compiler)
  17. goto b:
  18. a: first line of code
  19. ...rest of code
  20. b: if 0 eq 0 goto a
  21. continuation of code.
One line difference.
May 19 '10 #7
RedSon
5,000 Expert 4TB
jkmyoung,

I don't think anyone is disputing the difference in assembly. But the quote was:

No, because 'true' is a condition which must continue to be fulfilled for the loop to continue. Whereas with for(;;) some other statement in the body of the loop is required to stop it

which leads me to believe that the original poster of this quote thinks there is a difference in the c/c++. If we are all taking about the differences in assembly then I think we all agree.
May 19 '10 #8

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

Similar topics

2
by: VMI | last post by:
I'm having doubts as to how the compiler interprets this If statement: bool bIsTrue = true; if (! bIsTrue) { //RUN PROCESS } Here, will "RUN PROCESS" be executed? Or is this just wrong?...
1
by: Siva sakthi via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Siva sakthi Hi, I have populated the data from database in aspx page using template column.
6
by: kberry | last post by:
I am clearing Textboxes on a form... this is loop I have came up with but was wondering if it can be shorter or not as long... Can anyone help? Dim controlOnForm As Control 'Places a control...
4
by: sureshk | last post by:
In 'C' the signature of any function's prototype and the definiton of the function should match.But for function main may recieve the arguments or may not recieve the arguments 'It is optional'. How...
0
by: sathyakvani | last post by:
c we r creating web pages any body frm anywhere can access our web pages a pls clear my doubt and even how to develop websites so that every one an access
1
by: Prabhua | last post by:
Can anybody clear my doubt in sql query. i want to display distinct company from the database where status is not empty. here company and status are columes. a.prabhu
1
by: gkpandiforum | last post by:
Define 'continue' statement either in C or C++? And what is the difference between 'if' and 'switch' statements?
1
by: sugusaranya | last post by:
how to place an image and detects its edges using halftoning algorithm?
8
by: Bryan | last post by:
Hello all. I'm fairly new to c++. I've written several programs using std::vectors, and they've always worked just fine. Until today. The following is a snippet of my code (sorry, can't...
2
by: sathishc58 | last post by:
Hi All I recently studied about "Forest" Datastructures. Supposed we have two trees. Could not represent diagramatically Tree a ====== 1) 10 is the root node 2) 9 is the
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.