Easy For Loop won't work

Ok i run dry guys…
I have a REALLY simple snippet and it’s just don’t work.It appears it won’t loop and do the instructions inside it.

for (int i = 10; i <= 15; i++);
  {
    lcd.setCursor(i,0);
    lcd.print(" ");
    lcd.setCursor(i,1);
    lcd.print(" ");
  }

I tried with serial.print with some vars in it and it get’s in once and goes out.
I really don’t know what’s wrong or if I’m so newbie in c++

Remove the semicolon from this line:

for (int i = 10; i <= 15; i++);

Please post the ALL code that gives you the problem, and describe the problem. More hints on how to post successfully are given in the "How to use the forum" post.

ToddL1962:
Remove the semicolon from this line:

for (int i = 10; i <= 15; i++);

Ok,i’m idiot.
I have been looking at this code for over 3 hours,never thought about the semicolon.
God damn.
Thanks a lot!

This part will still work, even with the semicolon. But it will print at position i=16:

 {
    lcd.setCursor(i,0);
    lcd.print(" ");
    lcd.setCursor(i,1);
    lcd.print(" ");
  }

jremington:
This part will still work, even with the semicolon. But it will print at position i=16:

 {

lcd.setCursor(i,0);
    lcd.print(" “);
    lcd.setCursor(i,1);
    lcd.print(” ");
  }

This part is fully working now.
The issue was that the “for” repeat wasn’t working so it was doing’t it once and that’s all.The removal of the semicolon fixed everything

“ Ok,i'm idiot.
I have been looking at this code for over 3 hours,never thought about the semicolon.
God damn. ”

No need for this.

We have all done this except for: @Coding Badly and @TheMemberFormerlyKnownAsAWOL.

jremington:
This part will still work, even with the semicolon. But it will print at position i=16:

Not unless you have another i in scope, AND that i has a value of 16.

This i is local to the for code block (or rather null statement as it doesn’t have a code block due to the terminating semi-colon)…

for (int i = 10; i <= 15; i++);

Edit: Another good reason for NOT having globals (or other locals within the same scope) with the same name. Had you got “error: ‘i’ was not declared in this scope” you’d have found this a lot faster.

To the OP:
Where (and more importantly why) is “i” declared elsewhere in your full program that made your original snippet compile?

Can’t you just

for (int i = 10; i <= 15; i++)
  {
    lcd.setCursor(i,0);
    lcd.print("  "); // print two spaces
  }

?

pcbbc:
Not unless you have another i in scope, AND that i has a value of 16.

This i is local to the for code block (or rather null statement as it doesn’t have a code block due to the terminating semi-colon)…

for (int i = 10; i <= 15; i++);

Edit: Another good reason for NOT having globals (or other locals within the same scope) with the same name. Had you got “error: ‘i’ was not declared in this scope” you’d have found this a lot faster.

To the OP:
Where (and more importantly why) is “i” declared elsewhere in your full program that made your original snippet compile?

i’m pretty sure i declared “i” when i used it as byte type to create a custom char.This was out of loop() though

lavarsio:
i’m pretty sure i declared “i” when i used it as byte type to create a custom char.This was out of loop() though

A global then?

A couple of points…
a) Single letter variable names for globals are generally a very bad idea.
b) Duplicating a variable names for both a global AND a local is overwhelmingly bad.

It’s like calling both your children “Bob”. Perfectly legal, but you’d be crazy to try. Sooner or later you’d get completely muddled as to which “Bob” you are referring to.

Also i for a character is a strange choice. c would be my preference.

pcbbc:
A global then?

A couple of points....
a) Single letter variable names for globals are generally a very bad idea.
b) Duplicating a variable names for both a global AND a local is overwhelmingly bad.

It's like calling both your children "Bob". Perfectly legal, but you'd be crazy to try. Sooner or later you'd get completely muddled as to which "Bob" you are referring to.

Also i for a character is a strange choice. c would be my preference.

well i rarely do single letter var,but i was spelling logic in 8bit custom chars and it went like l/o/g/i/c.Meh

lavarsio:
well i rarely do single letter var,but i was spelling logic in 8bit custom chars and it went like l/o/g/i/c.Meh

Okay, understand.

I would have prefixed each with a common start: Eg. char_l, char_o etc.

Single letter variable names are for loop variables used as indices, and possibly very short lived parameters and local variables only. Otherwise, when used for globals, you possible get a scope conflict when you use one, and those can be very hard to spot (as you may have noticed).