473,406 Members | 2,336 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,406 software developers and data experts.

what does two semicolns ';;' do

I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?

I've tried to google it but the text filter seems to remove the
semicolons.
Jun 28 '08 #1
38 5978
la***@portcommodore.com wrote:
for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?
The two semicolons are *part* of the "for" construct. See any books on C or
C++ about "for" loops.

That means that the initial statement, the break condition and the loop
statement in that loop are the empty statement.

That means that the for loop does not initialize anything when starting,
does not check for any break condition, and does not perform anything at
the end of each loop.

Which means, that's an infinite loop (until it's broken by calling the
break() construct inside the loop)

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
Jun 28 '08 #2
la***@portcommodore.com wrote:
I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?

I've tried to google it but the text filter seems to remove the
semicolons.
Look up a for loop in the PHP doc. Three expressions, separated by
semicolons. In this case, the expressions are null (which is also valid).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 28 '08 #3
On Jun 28, 1:43*pm, la...@portcommodore.com wrote:
I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ * * // for([two semicolons){

what is the function of the two semicolons? *loop until break?

I've tried to google it but the text filter seems to remove the
semicolons.
yes, that's an infinite loop
Jun 28 '08 #4
la***@portcommodore.com wrote:
I am looking at some code which process an uploaded file and it has
loops like:
for(;;){ // for([two semicolons){
what is the function of the two semicolons? loop until break?
Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).
--
Jim Pennino

Remove .spam.sux to reply.
Jun 28 '08 #5
I figured that out soon after I posted it, not very apparent what it
it does though.

Thanks
Jun 29 '08 #6
la***@portcommodore.com wrote:
I figured that out soon after I posted it, not very apparent what it
it does though.

Thanks
Au contraire! It was **immediately** apparent to anyone who has done
any C, C++, Java, etc. coding.
Jun 29 '08 #7
ji**@specsol.spam.sux.com schrieb:
AIR for(;;) is slightly more efficient/faster than while(1).
How come? Isn't

for ( init; cond; after ) { stuff }

just syntactic sugar for

init; while ( cond ) { stuff; after }

and should therefore internally be the same?

Greetings,
Thomas
--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Jun 29 '08 #8
Thomas Mlynarczyk wrote:
ji**@specsol.spam.sux.com schrieb:
>AIR for(;;) is slightly more efficient/faster than while(1).

How come? Isn't [for] just syntactic sugar for [while] and should
therefore internally be the same?
It really depends on how your compiler optimizes jumps and boolean
expressions. A good compiler will know that both while(1) and for(;;) are
infinite loops and will translate them to non-conditional jumps in
assembler, effectively rendering them the same.

A bad compiler won't.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Cristo ha muerto por nuestros pecados, asÃ* que no vamos a frustrarle.
Jun 29 '08 #9
Iv??n S??nchez Ortega <ivansanchez-alg@rroba-escomposlinux.-.punto.-.orgwrote:
Thomas Mlynarczyk wrote:
ji**@specsol.spam.sux.com schrieb:
AIR for(;;) is slightly more efficient/faster than while(1).
How come? Isn't [for] just syntactic sugar for [while] and should
therefore internally be the same?
It really depends on how your compiler optimizes jumps and boolean
expressions. A good compiler will know that both while(1) and for(;;) are
infinite loops and will translate them to non-conditional jumps in
assembler, effectively rendering them the same.
A bad compiler won't.
And some compilers will recognize one but not the other.
--
Jim Pennino

Remove .spam.sux to reply.
Jun 29 '08 #10
On Jun 29, 4:20 am, sheldonlg <sheldonlgwrote:
la...@portcommodore.com wrote:
I figured that out soon after I posted it, not very apparent what it
it does though.
Thanks

Au contraire! It was **immediately** apparent to anyone who has done
any C, C++, Java, etc. coding.
Ya got me, I went from BASIC->6502 assembly->foxBase->PHP With a
little chipmunk BASIC along the way. :-)

Larry
Jun 29 '08 #11
Greetings, Ivan Sanchez Ortega.
In reply to Your message dated Saturday, June 28, 2008, 23:01:00,
>for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?
The two semicolons are *part* of the "for" construct. See any books on C or
C++ about "for" loops.
That means that the initial statement, the break condition and the loop
statement in that loop are the empty statement.
That means that the for loop does not initialize anything when starting,
does not check for any break condition, and does not perform anything at
the end of each loop.
Which means, that's an infinite loop (until it's broken by calling the
break() construct inside the loop)
Ridiculous usage of the language construct...
Why not use

while(true){ ... }

then?
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jun 30 '08 #12
ji**@specsol.spam.sux.com wrote:
>la***@portcommodore.com wrote:
>I am looking at some code which process an uploaded file and it has
loops like:
>for(;;){ // for([two semicolons){
>what is the function of the two semicolons? loop until break?

Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 30 '08 #13
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:
I am looking at some code which process an uploaded file and it has
loops like:
for(;;){ // for([two semicolons){
what is the function of the two semicolons? loop until break?
Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
True if there is optimization going on.
--
Jim Pennino

Remove .spam.sux to reply.
Jun 30 '08 #14
..oO(AnrDaemon)
>Greetings, Ivan Sanchez Ortega.
>Which means, that's an infinite loop (until it's broken by calling the
break() construct inside the loop)

Ridiculous usage of the language construct...
Why not use

while(true){ ... }

then?
Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.

Micha
Jun 30 '08 #15
In article <S9******************************@giganews.com>,
sheldonlg <sheldonlgwrote:
la***@portcommodore.com wrote:
I figured that out soon after I posted it, not very apparent what it
it does though.

Thanks

Au contraire! It was **immediately** apparent to anyone who has done
any C, C++, Java, etc. coding.
And supposing they haven't? Or supposing this question had been posed on
a C newsgroup, your response would have been *what* exactly?
Jun 30 '08 #16
In article <iv********************************@4ax.com>,
Michael Fesser <ne*****@gmx.dewrote:
.oO(AnrDaemon)
Greetings, Ivan Sanchez Ortega.
Which means, that's an infinite loop (until it's broken by calling the
break() construct inside the loop)
Ridiculous usage of the language construct...
Why not use

while(true){ ... }

then?

Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.
Not necessarily. I would always use while (true), as then you make
explicit what you are doing. Secondly, sure you have to break out of the
loop. But suppose there's a number of different reasons to do so? You're
not necessarily going to be able to choose one as the "main driver" of
the loop, which ought then to migrate into the loop construct?
Jun 30 '08 #17
..oO(Tim Streater)
>In article <iv********************************@4ax.com>,
Michael Fesser <ne*****@gmx.dewrote:
>Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.

Not necessarily. I would always use while (true), as then you make
explicit what you are doing. Secondly, sure you have to break out of the
loop. But suppose there's a number of different reasons to do so? You're
not necessarily going to be able to choose one as the "main driver" of
the loop, which ought then to migrate into the loop construct?
You could still find a better way to express the loop condition, even if
it's just a variable:

while (!$workIsDone) {
...
}

I admit that I also use break/continue from time to time, but I try to
avoid them because they often lead to hard to understand spaghetti code.
There's almost always a better way to structure the code.

Micha
Jun 30 '08 #18
Tim Streater wrote:
In article <S9******************************@giganews.com>,
sheldonlg <sheldonlgwrote:
>la***@portcommodore.com wrote:
>>I figured that out soon after I posted it, not very apparent what it
it does though.

Thanks
Au contraire! It was **immediately** apparent to anyone who has done
any C, C++, Java, etc. coding.

And supposing they haven't? Or supposing this question had been posed on
a C newsgroup, your response would have been *what* exactly?
It would have been RTFM or take course like C-101. This question was on
the level of "What is a for loop?".
Jun 30 '08 #19
Michael Fesser wrote:
.oO(Tim Streater)
>In article <iv********************************@4ax.com>,
Michael Fesser <ne*****@gmx.dewrote:
>>Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.
Not necessarily. I would always use while (true), as then you make
explicit what you are doing. Secondly, sure you have to break out of the
loop. But suppose there's a number of different reasons to do so? You're
not necessarily going to be able to choose one as the "main driver" of
the loop, which ought then to migrate into the loop construct?

You could still find a better way to express the loop condition, even if
it's just a variable:

while (!$workIsDone) {
...
}

I admit that I also use break/continue from time to time, but I try to
avoid them because they often lead to hard to understand spaghetti code.
There's almost always a better way to structure the code.

Micha
I agree. I never use while(true) or while(1), but opt for the
while ($somecondition) when I have to do this. That way there is an
explicit test at the top of the loop and I don't have to use "break". I
feel that the code is more readable if you can tell right away where the
next line is.
Jun 30 '08 #20
In article <g4********************************@4ax.com>,
Michael Fesser <ne*****@gmx.dewrote:
.oO(Tim Streater)
In article <iv********************************@4ax.com>,
Michael Fesser <ne*****@gmx.dewrote:
Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.
Not necessarily. I would always use while (true), as then you make
explicit what you are doing. Secondly, sure you have to break out of the
loop. But suppose there's a number of different reasons to do so? You're
not necessarily going to be able to choose one as the "main driver" of
the loop, which ought then to migrate into the loop construct?

You could still find a better way to express the loop condition, even if
it's just a variable:

while (!$workIsDone) {
...
}

I admit that I also use break/continue from time to time, but I try to
avoid them because they often lead to hard to understand spaghetti code.
There's almost always a better way to structure the code.
Here's some code from a simple app I am working on:

foreach ($attstrs as $nextatt)
{
if ($nextatt=='') continue;
$nextatt = "/Volumes/" . str_replace (":", "/", $nextatt);
$handle2 = fopen ($nextatt, "rb");
if ($handle2===false)
{
echo "Error - could not open attachment:\n '" . $nextatt .
"'\n";
continue;
}

...

}

Two continues in there. The alternative is to nest the code deeper,
something I avoid like the plague.
Jun 30 '08 #21
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
>ji**@specsol.spam.sux.com wrote:
>la***@portcommodore.com wrote:

I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?

Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).
>That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".

True if there is optimization going on.
Okay:

That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".

Better?

--
91. I will not ignore the messenger that stumbles in exhausted and obviously
agitated until my personal grooming or current entertainment is finished.
It might actually be important.
--Peter Anspach's list of things to do as an Evil Overlord
Jun 30 '08 #22
..oO(sheldonlg)
>Tim Streater wrote:
>And supposing they haven't? Or supposing this question had been posed on
a C newsgroup, your response would have been *what* exactly?

It would have been RTFM or take course like C-101. This question was on
the level of "What is a for loop?".
But only in C and the languages that were influenced by it. Other
languages use a totally different syntax (for example Pascal and its
derivates).

Micha
Jun 30 '08 #23
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:

I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?

Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
True if there is optimization going on.
Okay:
That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
Better?
You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
--
Jim Pennino

Remove .spam.sux to reply.
Jun 30 '08 #24
On Mon, 30 Jun 2008 15:05:02 GMT, ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
>On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:

I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?

Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).

That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".

True if there is optimization going on.
>Okay:
> That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
>Better?

You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
Exactly. Since we're presuming we don't know how clever the compiler is
exactly, it's therefore silly to claim that for(;;) is slightly more
efficient/faster than while(1). The compiler could handle both the same
way, in which case they'd be the same speed in execution.

--
Liberty, equality, diversity. Pick any two.
Jun 30 '08 #25
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 15:05:02 GMT, ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:

I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?

Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).

That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".

True if there is optimization going on.
Okay:
That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
Better?
You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
Exactly. Since we're presuming we don't know how clever the compiler is
exactly, it's therefore silly to claim that for(;;) is slightly more
efficient/faster than while(1). The compiler could handle both the same
way, in which case they'd be the same speed in execution.
Except in the terms of the original posting I seem to recall reading
somewhere that in the specific case of PHP for(;;) is slightly more
efficient.

I could, however, be experiencing a flash back from the 60's and be
wrong about that.
--
Jim Pennino

Remove .spam.sux to reply.
Jun 30 '08 #26
In all the examples of for, there were values other then just ;;, it
was a valid question. In other languages such a statement with nulls
instead of variables and values would rightly cause errors:

for = to : next
Jul 1 '08 #27
ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
>On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
>>Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:
>
>I am looking at some code which process an uploaded file and it has
>loops like:
>for(;;){ // for([two semicolons){
>what is the function of the two semicolons? loop until break?
Yeah, same as while (1) {.
>
AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
True if there is optimization going on.
>Okay:
> That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
>Better?

You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.

And that can screw you if you are - say - using i as an external global
variable, and setting it as a flag via an interrupt service routine.

Ther is some construct in C - is a it 'volatile'? - to tell the compiler
'this variable may change even if you cant see hwo' IIRC.

And it might have stuffed the value in an inaccessible register as well.


Jul 1 '08 #28
In article <12***************@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote:
ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:

I am looking at some code which process an uploaded file and it has
loops like:
for(;;){ // for([two semicolons){
what is the function of the two semicolons? loop until break?
Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
True if there is optimization going on.
Okay:
That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
Better?
You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
And that can screw you if you are - say - using i as an external global
variable, and setting it as a flag via an interrupt service routine.

Ther is some construct in C - is a it 'volatile'? - to tell the compiler
'this variable may change even if you cant see hwo' IIRC.

And it might have stuffed the value in an inaccessible register as well.
Presumably you could put it in a struct. Otherwise, yes, there's a
danger the variable gets optimised away.
Jul 1 '08 #29

Michael Fesser schreef:
.oO(Tim Streater)
>In article <iv********************************@4ax.com>,
Michael Fesser <ne*****@gmx.dewrote:
>>Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.
Not necessarily. I would always use while (true), as then you make
explicit what you are doing. Secondly, sure you have to break out of the
loop. But suppose there's a number of different reasons to do so? You're
not necessarily going to be able to choose one as the "main driver" of
the loop, which ought then to migrate into the loop construct?

You could still find a better way to express the loop condition, even if
it's just a variable:

while (!$workIsDone) {
...
}

I admit that I also use break/continue from time to time, but I try to
avoid them because they often lead to hard to understand spaghetti code.
There's almost always a better way to structure the code.

Micha
I totally utterly agree with Misha here.

If you write code try to make the logic/structure clear by picking nice
named variables, like $workIsDone.

What could possibly be the advantage of leaving them out?
Some misguided newbies might say 'for speed'.

Good programmers write clean code, not code that is 0.01% faster, but
clean code.
It is always a pleasure to read over code written by a programmer that
put some effort in it to make thing clear and simple.
It is a horror to read over (often buggy) code written by would-be
programmers that is aimed at speed (by sacrifying variables that help
understand the logic), or people trying to keep the sourcefiles as small
as possible.

Just my 2 cent.

Regards,
Erwin Moller
Jul 1 '08 #30
Erwin Moller wrote:
>
Michael Fesser schreef:
>.oO(Tim Streater)
>>In article <iv********************************@4ax.com>,
Michael Fesser <ne*****@gmx.dewrote:

Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.
Not necessarily. I would always use while (true), as then you make
explicit what you are doing. Secondly, sure you have to break out of
the loop. But suppose there's a number of different reasons to do so?
You're not necessarily going to be able to choose one as the "main
driver" of the loop, which ought then to migrate into the loop
construct?

You could still find a better way to express the loop condition, even if
it's just a variable:

while (!$workIsDone) {
...
}

I admit that I also use break/continue from time to time, but I try to
avoid them because they often lead to hard to understand spaghetti code.
There's almost always a better way to structure the code.

Micha

I totally utterly agree with Misha here.

If you write code try to make the logic/structure clear by picking nice
named variables, like $workIsDone.

What could possibly be the advantage of leaving them out?
Some misguided newbies might say 'for speed'.

Good programmers write clean code, not code that is 0.01% faster, but
clean code.
It is always a pleasure to read over code written by a programmer that
put some effort in it to make thing clear and simple.
It is a horror to read over (often buggy) code written by would-be
programmers that is aimed at speed (by sacrifying variables that help
understand the logic), or people trying to keep the sourcefiles as small
as possible.

Just my 2 cent.

Regards,
Erwin Moller
Add mine to make it 4 cents.
Jul 1 '08 #31
Tim Streater wrote:
In article <12***************@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote:
>ji**@specsol.spam.sux.com wrote:
>>Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
>ji**@specsol.spam.sux.com wrote:
>>la***@portcommodore.com wrote:
>>>
>>>I am looking at some code which process an uploaded file and it has
>>>loops like:
>>>for(;;){ // for([two semicolons){
>>>what is the function of the two semicolons? loop until break?
>>Yeah, same as while (1) {.
>>>
>>AIR for(;;) is slightly more efficient/faster than while(1).
>That's silly. Think about it for a moment. How on earth could that
>possibly be true? Both statements translate to exactly one assembly
>instruction: a "jmp".
True if there is optimization going on.
Okay:
That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
Better?
You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.

And that can screw you if you are - say - using i as an external global
variable, and setting it as a flag via an interrupt service routine.

Ther is some construct in C - is a it 'volatile'? - to tell the compiler
'this variable may change even if you cant see hwo' IIRC.

And it might have stuffed the value in an inaccessible register as well.

Presumably you could put it in a struct. Otherwise, yes, there's a
danger the variable gets optimised away.
Nope, if C the test could be optimized away, even if it's in a
structure. The people who write the optimizers are getting pretty good
at finding ways to make the code run smaller and faster. But they need
to because of the bloat caused by inefficient graphics and other system
code.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 1 '08 #32
In article <g4**********@registered.motzarella.org>,
Jerry Stuckle <js*******@attglobal.netwrote:
Tim Streater wrote:
In article <12***************@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote:
ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
>la***@portcommodore.com wrote:
>>
>>I am looking at some code which process an uploaded file and it has
>>loops like:
>>for(;;){ // for([two semicolons){
>>what is the function of the two semicolons? loop until break?
>Yeah, same as while (1) {.
>>
>AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
True if there is optimization going on.
Okay:
That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
Better?
You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
And that can screw you if you are - say - using i as an external global
variable, and setting it as a flag via an interrupt service routine.

Ther is some construct in C - is a it 'volatile'? - to tell the compiler
'this variable may change even if you cant see hwo' IIRC.

And it might have stuffed the value in an inaccessible register as well.
Presumably you could put it in a struct. Otherwise, yes, there's a
danger the variable gets optimised away.

Nope, if C the test could be optimized away, even if it's in a
structure. The people who write the optimizers are getting pretty good
at finding ways to make the code run smaller and faster. But they need
to because of the bloat caused by inefficient graphics and other system
code.
Fairy nuff. It's 20 years since I wrote any C :-)
Jul 1 '08 #33
In article <g4**********@registered.motzarella.org>,
Jerry Stuckle <js*******@attglobal.netwrote:
Tim Streater wrote:
In article <12***************@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote:
ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
>la***@portcommodore.com wrote:
>>
>>I am looking at some code which process an uploaded file and it has
>>loops like:
>>for(;;){ // for([two semicolons){
>>what is the function of the two semicolons? loop until break?
>Yeah, same as while (1) {.
>>
>AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
True if there is optimization going on.
Okay:
That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
Better?
You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
And that can screw you if you are - say - using i as an external global
variable, and setting it as a flag via an interrupt service routine.

Ther is some construct in C - is a it 'volatile'? - to tell the compiler
'this variable may change even if you cant see hwo' IIRC.

And it might have stuffed the value in an inaccessible register as well.
Presumably you could put it in a struct. Otherwise, yes, there's a
danger the variable gets optimised away.

Nope, if C the test could be optimized away, even if it's in a
structure. The people who write the optimizers are getting pretty good
at finding ways to make the code run smaller and faster. But they need
to because of the bloat caused by inefficient graphics and other system
code.
Fairy nuff. It's 20 years since I wrote any C :-)
Jul 1 '08 #34
On Mon, 30 Jun 2008 16:15:01 GMT, ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
>On Mon, 30 Jun 2008 15:05:02 GMT, ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:

I am looking at some code which process an uploaded file and it has
loops like:

for(;;){ // for([two semicolons){

what is the function of the two semicolons? loop until break?

Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).

That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".

True if there is optimization going on.

Okay:

That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".

Better?

You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
>Exactly. Since we're presuming we don't know how clever the compiler is
exactly, it's therefore silly to claim that for(;;) is slightly more
efficient/faster than while(1). The compiler could handle both the same
way, in which case they'd be the same speed in execution.

Except in the terms of the original posting I seem to recall reading
somewhere that in the specific case of PHP for(;;) is slightly more
efficient.
Clearly, that will depend on the compiler, neh?

(I think we are now in an infinate loop ourselves...)

--
"It's 106 light-years to Chicago, we've got a full chamber of anti-matter,
a half a pack of cigarettes, it's dark, and we're wearing visors."
"Engage."
Jul 1 '08 #35
Peter H. Coffin wrote:
(I think we are now in an infinate loop ourselves...)
Don't worry, I'm sure there will be somebody that will optimize us.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Perilous to all of us are the devices of an art deeper than we ourselves
possess.
-- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]

Jul 1 '08 #36
Greetings, Michael Fesser.
In reply to Your message dated Monday, June 30, 2008, 15:35:13,
>>Which means, that's an infinite loop (until it's broken by calling the
break() construct inside the loop)

Ridiculous usage of the language construct...
Why not use

while(true){ ... }

then?
Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.
True word, but sometimes it's usable (but must be avoided as possible).
If that's a required way to work, while(true) will be much more understandable
by anyone who will read the code in future.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jul 1 '08 #37
The Natural Philosopher <a@b.cwrote:
ji**@specsol.spam.sux.com wrote:
Peter H. Coffin <he*****@ninehells.comwrote:
On Mon, 30 Jun 2008 03:35:01 GMT, ji**@specsol.spam.sux.com wrote:
Tim Roberts <ti**@probo.comwrote:
ji**@specsol.spam.sux.com wrote:
la***@portcommodore.com wrote:

I am looking at some code which process an uploaded file and it has
loops like:
for(;;){ // for([two semicolons){
what is the function of the two semicolons? loop until break?
Yeah, same as while (1) {.

AIR for(;;) is slightly more efficient/faster than while(1).
That's silly. Think about it for a moment. How on earth could that
possibly be true? Both statements translate to exactly one assembly
instruction: a "jmp".
True if there is optimization going on.
Okay:
That's silly. Think about it for a moment. How on earth could that
possibly be reliably true? Both statements can easily translate to
exactly one assembly instruction: a "jmp".
Better?
You're missing the point.

While it is obviously true that whatever is translating the code COULD
do that, not all translators/compilers actually DO that.

Here's another case:

i=1;

while (i) {
// i never changes
}

Some compilers/translators will recognize this is an infinite loop
and some won't.

It all bepends on how clever the compiler/translator is.
And that can screw you if you are - say - using i as an external global
variable, and setting it as a flag via an interrupt service routine.
Ther is some construct in C - is a it 'volatile'? - to tell the compiler
'this variable may change even if you cant see hwo' IIRC.
And it might have stuffed the value in an inaccessible register as well.
Has everyone lost sight of the fact that this is a PHP group?

Does anyone have a clue what PHP actually does with stuff like this?

--
Jim Pennino

Remove .spam.sux to reply.
Jul 1 '08 #38
ji**@specsol.spam.sux.com wrote:
>
Has everyone lost sight of the fact that this is a PHP group?
Yeah, that occurred to be about 15 seconds after I posted my original
reply.
>Does anyone have a clue what PHP actually does with stuff like this?
That's a good question, and now I'm curious. Python has a way to dump the
byte code it generates in a relatively human-readable form. Does PHP have
the same thing?
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 2 '08 #39

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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...

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.