++operator

  • Thread starter Thread starter Crirus
  • Start date Start date
C

Crirus

There is any difference between

for (int line = 0; line < linesPerPage; ++line) {
}

and

for (int line = 0; line < linesPerPage; line++) {

}

?
 
Cirius,

Both of the followup posts to your question are correct. I just wanted to
clarify how the itterator in the for loop works out. The for loop consists
of four parts: 1. the initializer (int line = 0), the termation condition
(line < linesPerPage), the itterator (line++ or line++), and the statement
(everything within {}). In the scenario you presented there will be no
difference since the initalization and termination conditions are not
affected by the itteration statement. The itteration statement (++line) is
executed after the statement portion (everything within {}) of the for loop
is executed...since the iteration statement is not a compond statement
(i.e. it is on a line by itself) you'll se no difference between ++line and
line++.

Thanks! Robert Gruen
Microsoft, VB.NET

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
| From: "Christian" <[email protected]>
| References: <[email protected]>
| Subject: Re: ++operator
| Date: Mon, 25 Aug 2003 10:19:07 +0200
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: host114-198.pool21757.interbusiness.it 217.57.198.114
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:179105
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Cirius.
|
| in addition to what Rob said:
|
| in this specific case there are no differences, you could have difference
in
| a case like:
| int i = 0;
| ...
| int n = i++;
| // now n = 0, i = 1
| OR
| int i = 0;
| ...
| int n = ++i;
| // and now n = i = 1
|
|
| >
| > for (int line = 0; line < linesPerPage; ++line) {
| > }
| >
| > and
| >
| > for (int line = 0; line < linesPerPage; line++) {
| >
| > }
|
|
|
 
Back
Top