Local Scope ( why did this work?)

The question as I'm learning this lesson of local scope, the goal is to print "2."

I got it happening, but I like to know why because an error happened beforehand because, in the lesson, he had "<" as you can see below the first code that no longer works, but in his lesson, it did. I read line for line to make sure I wasn't crazy. then check it again

/Users/nicolasganea/Documents/Arduino/Hackster Activity 27 Local scope ( not global )/Hackster Activity 27 Local scope ( not global ).ino: In function 'void loop()':
/Users/nicolasganea/Documents/Arduino/Hackster Activity 27 Local scope ( not global )/Hackster Activity 27 Local scope ( not global ).ino:14:14: error: expected primary-expression before '<' token
for ( a = 0; < 3; a++) {
^
Compilation error: Error: 2 UNKNOWN: exit status 1

this was the code that didn't work

Preformatted textint i = 3;

void setup() {

// put your setup code here, to run once:

Serial.begin (9600);

//Serial.println(i);

}

void loop() {

// put your main code here, to run repeatedly:

int a = 0; // "a" is a "local variable"

//a++;

//Serial.println(a);

int b = 2; // How to fix the printing of just "1"

for ( a = 0; < 3; a++) {

Serial.println(b);

} // question why does < this no longer work?

delay(500);

}

Preformatted text

I experimented removing "<" it worked, allowing me to print "2" was there an update? if it was an update, is it faster to removing < less than? that's all that makes logical sense to me for such a thing I need to see the proof I don't like assumptions

Or maybe someone can see what I am not seeing.

(code that worked to printing 2)
Preformatted textint i = 3;

void setup() {

// put your setup code here, to run once:

Serial.begin (9600);

//Serial.println(i);

}

void loop() {

// put your main code here, to run repeatedly:

int a = 0; // "a" is a "local variable"

//a++;

//Serial.println(a);

int b = 2; // How to fix the printing of just "1"

for ( a = 0; 3; a++) {

Serial.println(b);

} // question why does < this no longer work?

delay(500);

}Preformatted text

Thank you for your time

Let’s start with basics C++ For Loop

The compiler tells you that you can’t write for ( a = 0; < 3; a++) {, that it is expecting some expression before the < symbol.

This would seem more appropriate
for ( a = 0; a < 3; a++) {

Ps: your file name is… interesting :upside_down_face:
Hackster Activity 27 Local scope ( not global )/Hackster Activity 27 Local scope ( not global ).ino

"for" statement:
for( [init-expression]; [conditional-expression]; [loop-expression] )

for ( a = 0; a < 3; a++)

The condition should be like this: a < 3.
"< 3" - there is nothing to compare with - error

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.