For loop not working... FIXED. thank you AWOL

here is the problem.

the var i will not increase.

my out put via Serial.

DIR= 1 steps= 15
15151515151515151515151515151515151515151515151515151515151515151515151515151515

Here is the code.

void setup(){
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
Serial.begin(9600);
}

void loop(){
  step(true,15);
}

void step(boolean dir,int steps){
  digitalWrite(8,dir);              // set the direction via call dir
  digitalWrite(7,HIGH);             // Set sleep on
  delay(50);
  Serial.print("DIR= ");
  Serial.print(dir);
  Serial.print(" steps= ");
  Serial.println(steps);
  for(int i=0;i = steps;i++){
      //CHSW();        // take time to check the button
      digitalWrite(9, HIGH);
      delayMicroseconds(90);
      digitalWrite(9, LOW);
      delayMicroseconds(90);
    Serial.print(i);
  } // END for(int i=0;i = steps;i++)
  digitalWrite(7,LOW);
  
} //END step(boolean dir,int steps)

Thanks for the help

i = steps

That's an assignment, not a comparison.
Rest assured, for loops do work.

(It's a kind of comparison; the assignment is done and the outcome is tested zero/non-zero)

Ok.

It would have been nice to see what it should have been.

i changed it to this.

for(int i=0;i <= steps;i++){

It works.

Thank you

for(int i=0;i = steps;i++){

should be
for(int i=0;i < steps;i++){

if you have declared steps[15] as an array

steps clearly isn't an array, but if you want fifteen steps, then yes, <= is incorrect.

steps is not an array.

steps = 15;
    for (int i = 0  ;        i <= steps           ;  i++       ) {
// for (start at 0; if i equals/same DO IT; add 1 to i) {
DO-IT();
}

This is how I understand it.

I will be making a different post. Its the original problem....

Dave

// for (start at 0; if i equals/same DO IT; add 1 to i) {

The middle clause is a while clause. Execute the body of the for statement while i is less than or equal steps.

thank you PaulS,
I did try <= >= != and so on. Here is what i found just minutes ago.
I changed for (int i=0;i<=steps;i++){ to a for(int i=0;i<=TheDelay;i++){ and it works great.

this was just a test but it worked. Is steps a reserved word? it did not turn red.

*TheDelay = 90

Any insight on why?

thanks

Is steps a reserved word?

No.

*TheDelay = 90

What does this mean? How is TheDelay declared?

Any insight on why?

On why what? You changed the code you initially posted, but haven't shown us the changed code. You can't reasonably expect us yo answer questions about code we can't see, can you?

Thanks for the response PaulS.

*TheDelay = 90 was not in a code window. So its not code. I was letting viewers know TheDelay equaled 90.
as for not showing the changes. Posted on: December 25, 2012, 03:04:40 PM

for(int i=0;i <= steps;i++){

Then i stated i was having a different problem. (well it was the first problem i did not post until now but was the main problem.)

I will be making a different post.

So i hope this clears thing up for you.

This question was answered.