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 1200
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******** *************@g 14g2000cwa.goog legroups.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.hc ltech.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 misunderstandin g
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 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>, <IDType2>. Because
both are identities and have some
commonality we can inherit them from a
base <Identity> type.
|
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) in the user's registry. The latest e-mail we received from development states:
"Launching help with a certain topic using a Map ID is not supported in the C#.NET API. Well there is always a work around but would violate the .NET help...
|
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.
Here is how you can reproduce it:
1. Create a form, in its properties, set the MinimizeBox and MaximizeBox to
|
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 treeview using delegates. But i still not found proper result
Pls help me. i need it immediatel
|
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 any help...
Error:
-----
| |
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 context help with that particular
command.
In VB6 this was easy, since each menu item had a "helpId" property. That
doesn't seem to be the case in VB.NET. Am I wrong about that, or
(alternatively) is there some other way to accomplish this?
--
|
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 field should be mytime..
I am getting error Data type mismatch in criteria expression. in EXEC
I really appreciate if anyone can help me.
Thanks in advance
|
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
my runtime working ,thank you very much!if you can help directly i will
die for you .haha ,thanks very much!
|
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 which would take
in as input the state code, of the 50 states belonging to the Unites
States of America. After the user enters the two letter code and
presses the "GO" button, a *.xsd file is parsed to retrieve
information about the entire state...
|
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 clicking the ? Contents on the toolbar, the HTML Help program runs. My problem is that the links to related items appears as a box with a dot in the middle. Not only to they appear as a box but clicking on them produces no result. This install (XP &...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |