473,657 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help! "for (;;)"?

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!

Nov 22 '05 #1
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

Nov 22 '05 #2

"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>
Nov 22 '05 #3
In only five minutes I've got two answers to my question. This is
great! :)

Thank you very much!
¡Muchas gracias!

Nov 22 '05 #4
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

Nov 22 '05 #5
Your example is very welcome.

Again, thanks!

Nov 22 '05 #6
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
Nov 22 '05 #7

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

Nov 22 '05 #8

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

Nov 22 '05 #9
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
Nov 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1092
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.
1
4045
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...
0
1616
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
1
315
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
8
1821
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: -----
4
4140
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? --
3
1819
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
2
1186
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!
2
1719
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...
2
1368
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 &...
0
8842
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8516
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,...
0
8617
tracyyun
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...
0
7353
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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...
1
2743
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
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.