index scopein the for loop

Ok, this must be the biggest dumb noob question of the year. But why does:
for (int index = 0; index<4; index++);
{
pinMode(padPins[index], INPUT);
}
Give me a big fat error message, when:

int index = 0;
for (index = 0; index<4; index++);
{
pinMode(padPins[index], INPUT);
}

works.
This is the error message:

padtest1.cpp: In function ‘void setup()’:
padtest1:23: error: invalid types ‘int [4][char* ()(const char*, int)]’ for array subscript

Boy, I hope something simple is wrong with my syntax, because the reference says the definition inside the for should work, as do all the examples in this expensive book I bought…
Thanks
Don

Get rid of the trailing semi-colon on your for statement.

Please edit your post to enclose your code in code blocks, so it looks

like this

Get rid of the trailing semi-colon on your for statement.

Necessary, but why? Because the semicolon defines the body of the if statement. Then, you have another block that references the variable, index, that has gone out of scope, because the if statement has ended.

In the second example, the index variable is not defined as part of the if statement, so it is still in scope after the if statement ends.

Knew it was something stupid, I'm not used to C-style programming, having done most of mine in (gasp) Fortran and Forth. Thanks, and I'll remember about the code snippets. Don

I have a lot of old Fortran code that I still need to run/modify once in a while. Takes me forever to get back in the mode where programming in Fortran is as effortless as programming in C++ now is. Learning C++ in the first place was a challenge, but I’ve had 20+ years to get used to it.

buffler: padtest1:23: error: invalid types 'int [4][char* ()(const char*, int)]' for array subscript

Incidentally, none of this explains this crazy error message. If you try compiling the erroneous code, but simply COMMENT OUT the bogus for line, the compiler gives the message I expect, "'index' was not declared in this scope".

Nothing in the snippet posted does. But, if index had some crazy global definition as an array, that would likely result in that compiler message.

Which, of course, is why we don't like diagnosing problems based on snippets. Post all of the code.

Not that I consider myself a compenent programmer yet, but I found C/C++ not to be too hard because the first programming language I tried seriously to learn was Pascal (turbo pascal on CP/M and later PC) so I mainly just had to unlearn begin and end with { and } :D

Lefty

the first programming language I tried seriously to learn was Pascal (turbo pascal on CP/M and later PC)

I think most people that tried that gave up, and changed careers.

PaulS:

the first programming language I tried seriously to learn was Pascal (turbo pascal on CP/M and later PC)

I think most people that tried that gave up, and changed careers.

Well it wasn't a career choice, it was a hobby. Hardware was my career. :D

However at the time there was no other compilers avalible at near it's $50 price, so a good choice for me at the time compaired to all the typical basic languages avalible. Besides didn't turbo pascal eventually morph into becoming Delphi? Seems there are still people making a living using Delphi?

Lefty