Novice needs help

This code comes from the examples provided.

I would like to know how to change this code to exicute x number of times and then move on to something else like a different sequence , or even just stop. I am guessing that I need to remove the "void loop()" statement, but when I do that I get errors. I do not know how to fix.
I know that this is probably a very basic question and that I should be able to figure this out for myself, but all of my efforts have failed.

/*

int timer = 100; // The higher the number, the slower the timing.
int pins[] = { 2, 3, 4, 5, 6, 7 }; // an array of pin numbers
int num_pins = 6; // the number of pins (i.e. the length of the array)

void setup()
{
int i;

for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num_pins - 1
pinMode(pins*, OUTPUT); // set each pin as an output*
}
void loop()
{

  • int i;*

  • for (i = 0; i < num_pins; i++) { // loop through each pin...*
    _ digitalWrite(pins*, HIGH); // turning it on,_
    _
    delay(timer); // pausing,_
    _ digitalWrite(pins, LOW); // and turning it off.
    }_
    for (i = num_pins - 1; i >= 0; i--) {
    _ digitalWrite(pins, HIGH);
    delay(timer);
    digitalWrite(pins, LOW);
    }
    }*_

Hello,

For starters all sketches require a loop. I recommend you read the contents of this link http://www.arduino.cc/en/Tutorial/Sketch , especially the last part entitled "setup() and loop()"

Another good piece of reading material is this http://www.freeduino.org/files/arduino_notebook_v1-1.pdf , if you read the section entitled "for" on page 21 you will understand

how to change this code to exicute x number of times and then move on to something else like a different sequence , or even just stop.

change this code to exicute x number of times and then move on to something else like a different sequence , or even just stop.

There are a lot of ways you can do this.
First of all, a microcontroller like arduino never really "stops" the way a computer program on a desktop PC would stop. The easiest thing to do is to make it DO NOTHING, FOREVER:

void stop()
{
 while (1) {   // Do forever
    ;          // nothing
 }
}

To get the code to do something several times, do something like the following:

void loop()
{
   int i;
   int ntimes;

  for (ntimes = 0; ntimes < 20; ntimes++) {
    for (i=0 .... // The current contents of loop goes here
    } // end of "i" loops (from existing code)
  } // end of "ntimes" loop
// Do something else here, if you want.
  stop();
}

Another good way to mimic the behavior of a "conventional" PC-type program is to simply make an empty loop function, for example

void setup()
{
  // do something
  ...
  // do something else
  ...
  for (int i=0; i<10; ++i)
  {
    // do something 10 times
    ...
  }
  // do one last thing
  ...
}

// Don't do anything here... (stop!)
void loop()
{
}

Mikal