preset counter variable in a for loop

2020-02-28 Thread Namal via Digitalmars-d-learn
Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Same works perfectly fine in C++ #include int main(){ int i = 0; for(i; i<3; i++) std::cout<

Re: preset counter variable in a for loop

2020-02-28 Thread mipri via Digitalmars-d-learn
On Friday, 28 February 2020 at 12:44:52 UTC, Namal wrote: Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Well, that's the error. b has no effect

Re: preset counter variable in a for loop

2020-02-28 Thread Namal via Digitalmars-d-learn
On Friday, 28 February 2020 at 12:48:17 UTC, mipri wrote: On Friday, 28 February 2020 at 12:44:52 UTC, Namal wrote: Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error

preset counter variable in a for loop --> 'has no effect' Error

2020-02-28 Thread Namal via Digitalmars-d-learn
Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Same works perfectly fine in C++ #include int main(){ int i = 0; for(i; i<3; i++) std::cout<

Re: preset counter variable in a for loop --> 'has no effect' Error

2020-02-28 Thread drug via Digitalmars-d-learn
On 2/28/20 11:48 AM, Namal wrote: Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){  int b = 0;  for (b; b<3; b++){    writeln(b);  } } $Error: b has no effect Same works perfectly fine in C++ #include int main(){  int i = 0;