Hi everybody!
I've got a very simple, but very difficult to me, question: can anybody
explain me this?
for (;;)
{
(...)
}
I just don't get it. Inside the loop, I've got a couple of "break".
Thank you for your help! 10 1189
Perro Flaco wrote: Hi everybody!
I've got a very simple, but very difficult to me, question: can anybody explain me this?
for (;;) { (...) }
I just don't get it. Inside the loop, I've got a couple of "break".
Thank you for your help!
It's an infinite loop (same as "while(true) { /*...*/ }"). The "break"s
are the only way to get out of it.
Cheers! --M
"Perro Flaco" <fa****************@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com... Hi everybody!
I've got a very simple, but very difficult to me, question: can anybody explain me this?
for (;;)
The above line starts the loop. The is no exit condition so the loop will go
on forever -- unless you "break" out of it.
{ (...) }
Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
In only five minutes I've got two answers to my question. This is
great! :)
Thank you very much!
¡Muchas gracias!
This is called a mid-test loop or multi-exit loop. It can be used to
avoid a common software engineering problem: duplicate code.
For example,
read(input, d)
while (!eof(input)) do
do something with d;
read(input, d);
end
- here, read(input, d) is duplicated.
vs.
while(true) do
read(input, d);
if(eof(input)) break;
do something with d;
end
- here there's no code duplication
Your example is very welcome.
Again, thanks!
mlimber wrote: It's an infinite loop (same as "while(true) { /*...*/ }"). The "break"s are the only way to get out of it.
Well, not the "only" way. You could issue a 'return' (heck even a
'goto'...yikes) or more importantly an exception might be thrown
implicitly by other code in the loop; perhaps in a completely different
source module. Always consider exceptions and what they might do.
--
Regards,
Ferdi Smit (M.Sc.)
Email: Fe********@cwi.nl
Room: C0.07 Phone: 4229
INS3 Visualization and 3D Interfaces
CWI Amsterdam, The Netherlands
Kwan Lim wrote: This is called a mid-test loop or multi-exit loop. It can be used to avoid a common software engineering problem: duplicate code. For example,
read(input, d) while (!eof(input)) do do something with d; read(input, d); end
- here, read(input, d) is duplicated.
vs.
while(true) do read(input, d); if(eof(input)) break; do something with d; end
- here there's no code duplication
I am changing the subject here so not detracting from your point at all
....
I think it's worth mentioning that with C++ streams that pseudo-code
should look like this (note: still no code duplication)
while (read(input, d))
do something with d
end
if (!eof(input)) ... something went wrong reading from the stream
I want to make that point because there is a common misunderstanding
about how to use eof with streams.
Gavin Deane
Ferdi Smit wrote: mlimber wrote: It's an infinite loop (same as "while(true) { /*...*/ }"). The "break"s are the only way to get out of it.
Well, not the "only" way. You could issue a 'return' (heck even a 'goto'...yikes) or more importantly an exception might be thrown implicitly by other code in the loop; perhaps in a completely different source module. Always consider exceptions and what they might do.
Always write exception safe code so you never have to worry about what
exceptions might do :-)
Gavin Deane
Kwan Lim wrote: This is called a mid-test loop or multi-exit loop. It can be used to avoid a common software engineering problem: duplicate code. For example,
read(input, d) while (!eof(input)) do do something with d; read(input, d); end
- here, read(input, d) is duplicated.
vs.
while(true) do read(input, d); if(eof(input)) break; do something with d; end
- here there's no code duplication
I think a better solution in this case and many similar others is something
like that (pseudocode):
bool read_eof (input, d)
{
read (input, d);
return ! eof (input);
}
while (read_eof (input, d) )
do_something;
--
Salu2
Julián Albo wrote: while(true) do read(input, d); if(eof(input)) break; do something with d; end
- here there's no code duplication
I think a better solution in this case and many similar others is something like that (pseudocode):
bool read_eof (input, d) { read (input, d); return ! eof (input); }
while (read_eof (input, d) ) do_something;
Actually this is not a better solution in C++.
The main problem is, that you still try to use eof()
for controlling the loop.
There is nothing wrong with what Deane posted
and it is the way to go:
while( read( input, d ) )
do_something;
if( !eof( input ) )
something_went_wrong;
Note that this loop terminates even if some other thing
then eof() happens. Things like: user removed device (floppy, cd,
memory stick, ...) during the read operation, the network connection
broke down, the modem had a transmission failure, phone line broke
or simply a bad block on the hard disc.
--
Karl Heinz Buchegger kb******@gascad.at This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: KK |
last post by:
Design Pattern help for this scenerio?.
I need some expert advice on possible ways
to design the classes for following scenerio.
Subject domain has 3 types of identities.
Lets say <IDType1>,...
|
by: Denise L. Moss-Fritch |
last post by:
Has anyone developed context sensitive help for a C# application? According to our programming staff, the development side is not able to provide links without adding hard coded links (topic names)...
|
by: Renee |
last post by:
Hi there,
does any one know how to create context sensitive help for Groupbox control
with HelpProvider class?
I can create context sensitive help for any control easily except for
Groupbox.
...
|
by: Jigar Shah |
last post by:
hello
i want to make a forum in my site which shows message posts and its total replies. So i had put treeview (IE Web Controls) in datagrid. I need help for that. I am attaching events to...
|
by: Tim::.. |
last post by:
Can someone please tell me why I keep getting the following error for some of
my web application users but not others??? Even though the application runs
from a central webserver???
Thanks for...
| |
by: Bob Homes |
last post by:
In VB6, I used a system, which I loved, whereby I assigned a "helpId" to each
menu item; that way, you could rest the cursor on the item (without actually
running it) and then press F1 to get...
|
by: shakir |
last post by:
HI All,
I need help for inserting recods into the access database using python
script through ODBC. I can insert data without any problem if I hard
coded the run_Date field. But I need run_Date...
|
by: lovesehuang |
last post by:
need some help for source codes about Keep Data Secret Management
System baseed on C/S Architecture.The other thnics we need is
SQL,C++,VC++,can u tell me where can i get them or download them.it's...
|
by: MK |
last post by:
Hello,
I am new to XML and PERL and I have a few questions the answers to
which I need to complete a project. All your time and effort would be
highly appreciated. I have to make a small HTML page...
|
by: DanO |
last post by:
Missing links in HTML Help for VB 6
Windows XP 5.1.2600 SP2
VB 6 (SP6) Professional Edition
HTML Help Control Version 5.2.3790.2847
MSDN Library Visual Studio 6.0
When in the VB IDE, F1 or...
|
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,...
| |
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...
|
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,...
|
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,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |