Message error Help

Please help me find the error it says function definition is not allowed here before { token

void foo (int bar) {
for (int foo=0; foo<10; foo++) {
if (foo==bar)
break;
}
Serial.print(“Foo era “);
Serial.println(foo);
return foo;
}

First issue:

for (int foo=0; foo<10; foo++) {
if (foo==bar)
break;
}

The variable foo is declared inside the for statement and therefore not visible outside the {}.

When the program code is at the two statements below, foo the variable does no longer exists. And this is meant literally. The compiler could store the value in the processor registers and not even store it intermediately in memory. So as soon as the loop is finished the compiler can use the CPU register for something else.

Serial.println( foo );
return foo;

If you declare the variable outside the loop you can still access it when you leave the loop

int foo;
for ( foo = 0; foo < 10; foo++ )
{
if ( foo == bar )
break;
}
Serial.println( foo );

Second issue:

Your function declaration means your function is not returning a value.

void foo()

Solution:

int foo()

Additionally, you declared a variable foo and a function foo. Makes your code hard to read and it is easy to make mistakes.