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. | | | | re: what does two semicolns ';;' do larry@portcommodore.com wrote: Quote:
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_eat_s_p_a_m_for_breakfast@hotmail.com
Jabber:ivansanchez@jabber.org ; ivansanchez@kdetalk.net | | | | re: what does two semicolns ';;' do larry@portcommodore.com wrote: Quote:
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. jstucklex@attglobal.net
================== | | | | re: what does two semicolns ';;' do
On Jun 28, 1:43*pm, la...@portcommodore.com wrote: Quote:
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 | | | | re: what does two semicolns ';;' do larry@portcommodore.com wrote: Quote:
I am looking at some code which process an uploaded file and it has
loops like:
Quote:
for(;;){ // for([two semicolons){
Quote:
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. | | | | re: what does two semicolns ';;' do
I figured that out soon after I posted it, not very apparent what it
it does though.
Thanks | | | | re: what does two semicolns ';;' do larry@portcommodore.com wrote: Quote:
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. | | | | re: what does two semicolns ';;' do jimp@specsol.spam.sux.com schrieb: Quote:
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) | | | | re: what does two semicolns ';;' do
Thomas Mlynarczyk wrote: Quote: jimp@specsol.spam.sux.com schrieb:
> Quote:
>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. | | | | re: what does two semicolns ';;' do
Iv??n S??nchez Ortega <ivansanchez-alg@rroba-escomposlinux.-.punto.-.orgwrote: Quote:
Thomas Mlynarczyk wrote:
Quote: Quote: jimp@specsol.spam.sux.com schrieb: Quote:
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?
Quote:
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.
Quote:
A bad compiler won't.
And some compilers will recognize one but not the other.
--
Jim Pennino
Remove .spam.sux to reply. | | | | re: what does two semicolns ';;' do
On Jun 29, 4:20 am, sheldonlg <sheldonlgwrote: Quote:
la...@portcommodore.com wrote: Quote:
I figured that out soon after I posted it, not very apparent what it
it does though.
> >
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 | | | | re: what does two semicolns ';;' do
Greetings, Ivan Sanchez Ortega.
In reply to Your message dated Saturday, June 28, 2008, 23:01:00, Quote: Quote:
>for(;;){ // for([two semicolons){
>>
>what is the function of the two semicolons? loop until break?
Quote:
The two semicolons are *part* of the "for" construct. See any books on C or
C++ about "for" loops.
Quote:
That means that the initial statement, the break condition and the loop
statement in that loop are the empty statement.
Quote:
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.
Quote:
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 <anrdaemon@freemail.ru> | | | | re: what does two semicolns ';;' do jimp@specsol.spam.sux.com wrote: Quote:
>larry@portcommodore.com wrote:
> Quote:
>I am looking at some code which process an uploaded file and it has
>loops like:
> Quote:
>for(;;){ // for([two semicolons){
> Quote:
>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, timr@probo.com
Providenza & Boekelheide, Inc. | | | | re: what does two semicolns ';;' do
Tim Roberts <timr@probo.comwrote: Quote: jimp@specsol.spam.sux.com wrote: Quote:
larry@portcommodore.com wrote: Quote:
I am looking at some code which process an uploaded file and it has
loops like:
Quote:
for(;;){ // for([two semicolons){
Quote:
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).
Quote:
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. | | | | re: what does two semicolns ';;' do
..oO(AnrDaemon) Quote:
>Greetings, Ivan Sanchez Ortega.
> Quote:
>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 | | | | re: what does two semicolns ';;' do
In article <S9adnQoqtOOT7frVnZ2dnUVZ_v7inZ2d@giganews.com>,
sheldonlg <sheldonlgwrote: Quote: larry@portcommodore.com wrote: Quote:
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? | | | | re: what does two semicolns ';;' do
In article <ivgh64ll18rvnv95q6noc13cadab4r17uh@4ax.com>,
Michael Fesser <netizen@gmx.dewrote: Quote:
.oO(AnrDaemon)
> Quote:
Greetings, Ivan Sanchez Ortega. Quote:
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? | | | | re: what does two semicolns ';;' do
..oO(Tim Streater) Quote:
>In article <ivgh64ll18rvnv95q6noc13cadab4r17uh@4ax.com>,
Michael Fesser <netizen@gmx.dewrote:
> Quote:
>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 | | | | re: what does two semicolns ';;' do
Tim Streater wrote: Quote:
In article <S9adnQoqtOOT7frVnZ2dnUVZ_v7inZ2d@giganews.com>,
sheldonlg <sheldonlgwrote:
> Quote:
> larry@portcommodore.com wrote: Quote:
>>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?". | | | | re: what does two semicolns ';;' do
Michael Fesser wrote: Quote:
.oO(Tim Streater)
> Quote:
>In article <ivgh64ll18rvnv95q6noc13cadab4r17uh@4ax.com>,
>Michael Fesser <netizen@gmx.dewrote:
>> Quote:
>>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. | | | | re: what does two semicolns ';;' do
In article <g4kh6453kqnfu1lddaee4qi6407mkovt76@4ax.com>,
Michael Fesser <netizen@gmx.dewrote: Quote:
.oO(Tim Streater)
> Quote:
In article <ivgh64ll18rvnv95q6noc13cadab4r17uh@4ax.com>,
Michael Fesser <netizen@gmx.dewrote: Quote:
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. | | | | re: what does two semicolns ';;' do
On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote: Quote:
Tim Roberts <timr@probo.comwrote: Quote:
> jimp@specsol.spam.sux.com wrote: Quote:
>larry@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).
> Quote:
>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 | | | | re: what does two semicolns ';;' do
..oO(sheldonlg) Quote:
>Tim Streater wrote:
> Quote:
>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 | | | | re: what does two semicolns ';;' do
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote: Quote:
Tim Roberts <timr@probo.comwrote: Quote: jimp@specsol.spam.sux.com wrote:
larry@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).
Quote:
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.
Quote:
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".
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. | | | | re: what does two semicolns ';;' do
On Mon, 30 Jun 2008 15:05:02 GMT, jimp@specsol.spam.sux.com wrote: Quote:
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
>On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote: Quote:
Tim Roberts <timr@probo.comwrote:
> jimp@specsol.spam.sux.com wrote:
>larry@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.
> > Quote:
> 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".
> >
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. | | | | re: what does two semicolns ';;' do
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
On Mon, 30 Jun 2008 15:05:02 GMT, jimp@specsol.spam.sux.com wrote: Quote:
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote:
Tim Roberts <timr@probo.comwrote: jimp@specsol.spam.sux.com wrote:
larry@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.
Quote:
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".
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.
Quote:
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. | | | | re: what does two semicolns ';;' do
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 | | | | re: what does two semicolns ';;' do jimp@specsol.spam.sux.com wrote: Quote:
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
>On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote: Quote:
>>Tim Roberts <timr@probo.comwrote:
>>> jimp@specsol.spam.sux.com wrote:
>>>> larry@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.
> > Quote:
> 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".
> >
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. | | | | re: what does two semicolns ';;' do
In article <1214908510.5119.4@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote: Quote: jimp@specsol.spam.sux.com wrote: Quote:
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote:
>Tim Roberts <timr@probo.comwrote:
>> jimp@specsol.spam.sux.com wrote:
>>> larry@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.
Quote:
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".
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. | | | | re: what does two semicolns ';;' do
Michael Fesser schreef: Quote:
.oO(Tim Streater)
> Quote:
>In article <ivgh64ll18rvnv95q6noc13cadab4r17uh@4ax.com>,
>Michael Fesser <netizen@gmx.dewrote:
>> Quote:
>>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 | | | | re: what does two semicolns ';;' do
Erwin Moller wrote: Quote:
>
Michael Fesser schreef: Quote:
>.oO(Tim Streater)
>> Quote:
>>In article <ivgh64ll18rvnv95q6noc13cadab4r17uh@4ax.com>,
>>Michael Fesser <netizen@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. | | | | re: what does two semicolns ';;' do
Tim Streater wrote: Quote:
In article <1214908510.5119.4@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote:
> Quote:
> jimp@specsol.spam.sux.com wrote: Quote:
>>Peter H. Coffin <hellsop@ninehells.comwrote:
>>>On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote:
>>>>Tim Roberts <timr@probo.comwrote:
>>>>> jimp@specsol.spam.sux.com wrote:
>>>>>> larry@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. jstucklex@attglobal.net
================== | | | | re: what does two semicolns ';;' do
In article <g4dgd6$o0u$2@registered.motzarella.org>,
Jerry Stuckle <jstucklex@attglobal.netwrote: Quote:
Tim Streater wrote: Quote:
In article <1214908510.5119.4@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote: Quote: jimp@specsol.spam.sux.com wrote:
>Peter H. Coffin <hellsop@ninehells.comwrote:
>>On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote:
>>>Tim Roberts <timr@probo.comwrote:
>>>> jimp@specsol.spam.sux.com wrote:
>>>>> larry@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 :-) | | | | re: what does two semicolns ';;' do
In article <g4dgd6$o0u$2@registered.motzarella.org>,
Jerry Stuckle <jstucklex@attglobal.netwrote: Quote:
Tim Streater wrote: Quote:
In article <1214908510.5119.4@proxy00.news.clara.net>,
The Natural Philosopher <a@b.cwrote: Quote: jimp@specsol.spam.sux.com wrote:
>Peter H. Coffin <hellsop@ninehells.comwrote:
>>On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote:
>>>Tim Roberts <timr@probo.comwrote:
>>>> jimp@specsol.spam.sux.com wrote:
>>>>> larry@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 :-) | | | | re: what does two semicolns ';;' do
On Mon, 30 Jun 2008 16:15:01 GMT, jimp@specsol.spam.sux.com wrote: Quote:
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
>On Mon, 30 Jun 2008 15:05:02 GMT, jimp@specsol.spam.sux.com wrote: Quote:
Peter H. Coffin <hellsop@ninehells.comwrote:
>On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote:
Tim Roberts <timr@probo.comwrote:
> jimp@specsol.spam.sux.com wrote:
>larry@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.
> Quote:
>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." | | | | re: what does two semicolns ';;' do
Peter H. Coffin wrote: Quote:
(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"] | | | | re: what does two semicolns ';;' do
Greetings, Michael Fesser.
In reply to Your message dated Monday, June 30, 2008, 15:35:13, Quote: Quote: Quote:
>>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?
Quote:
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 <anrdaemon@freemail.ru> | | | | re: what does two semicolns ';;' do
The Natural Philosopher <a@b.cwrote: Quote: jimp@specsol.spam.sux.com wrote: Quote:
Peter H. Coffin <hellsop@ninehells.comwrote: Quote:
On Mon, 30 Jun 2008 03:35:01 GMT, jimp@specsol.spam.sux.com wrote:
>Tim Roberts <timr@probo.comwrote:
>> jimp@specsol.spam.sux.com wrote:
>>> larry@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.
Quote:
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".
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.
Quote:
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.
Quote:
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. | | | | re: what does two semicolns ';;' do jimp@specsol.spam.sux.com wrote: Quote:
>
>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. Quote:
>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, timr@probo.com
Providenza & Boekelheide, Inc. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,467 network members.
|