H
hprYeV
I have done a reasonable amount of programming in C++,
but the other day I was talking to someone after a
lecture in a course on Java who said that they had not been
used to the syntax of the Java for loop because they always
had been programming in C++. I asked them what it was
they had not been used to, and they said that in C++ you
can use commas to separate the initial statement, the
condition, and the loop statement like this:
for(i=0,i<10,i++)
{ cout<<"hello"<<i<<endl; }
I then thought that maybe what they were thinking of
was this kind of statement
for(i=0,j=5;i<20;i++,j++)
{ cout<<i<<" "<<j<<endl; }
But he reiterated that it was the previous form, that
you can separate the condition and the initial and loop
statements with just a comma. I have never seen this.
I'd tried implementing this in the GNU implementation of
C++, and as I suspected, it returned an error.
I then concluded that he had been using an implementation
of C++ that allows this (which?). Interestingly, he said
he never used the semicolon ( for a for loop in C++ once.
Thanks for any insight.
but the other day I was talking to someone after a
lecture in a course on Java who said that they had not been
used to the syntax of the Java for loop because they always
had been programming in C++. I asked them what it was
they had not been used to, and they said that in C++ you
can use commas to separate the initial statement, the
condition, and the loop statement like this:
for(i=0,i<10,i++)
{ cout<<"hello"<<i<<endl; }
I then thought that maybe what they were thinking of
was this kind of statement
for(i=0,j=5;i<20;i++,j++)
{ cout<<i<<" "<<j<<endl; }
But he reiterated that it was the previous form, that
you can separate the condition and the initial and loop
statements with just a comma. I have never seen this.
I'd tried implementing this in the GNU implementation of
C++, and as I suspected, it returned an error.
I then concluded that he had been using an implementation
of C++ that allows this (which?). Interestingly, he said
he never used the semicolon ( for a for loop in C++ once.
Thanks for any insight.