I need programming help

void setup() {
// initialize the digital pin as an output.
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
int i=0;
//revolve three revolutions clockwise
for(i=0;i<1536;i++){
clockwiserotate();}
delay(100); // wait for a second
//revolve zero revolutions counterclockwise
for(i=0;i<000;i++){
counterclockwiserotate();}
delay(1000); // wait for a second
}
void clockwiserotate() { //revolve clockwise
step1();
step2();
step3();
step4();
step5();
step6();
step7();
step8();
}
void counterclockwiserotate() { //revolve counterclockwise
step1();
step7();
step6();
step5();
step4();
step3();
step2();
step1();
}
void step1(){
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2);
}
void step2(){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2);
}
void step3(){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2);
}
void step4(){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(2);
}
void step5(){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(2);
}

void step6(){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
delay(2);
}
void step7(){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(2);
}
void step8(){
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(2);
}

/*
The program must stop here.
Later: An external switch will restart the program.
Now the program will continue with the bottom part and stop.
Start and stop POSITIONS of stepper rotation not relevant.
At the end of the bottom cycle I am able to switch off
power to the Arduino Uno board.
I can resupply power to start the top part of the program.
Not very important: I would prefer to use Servos.
*/

void setup() {
// initialize the digital pin as an output.
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
int i=0;
//revolve zero revolutions clockwise
for(i=0;i<000;i++){
clockwiserotate();}
delay(1000); // wait for a second
//revolve three revolutions counterclockwise
for(i=0;i<1536;i++){
counterclockwiserotate();}
delay(1000); // wait for a second
}
void clockwiserotate() { //revolve clockwise
step1();
step2();
step3();
step4();
step5();
step6();
step7();
step8();
}
void counterclockwiserotate() { //revolve counterclockwise
step1();
step7();
step6();
step5();
step4();
step3();
step2();
step1();
}
void step1(){
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2);
}
void step2(){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2);
}
void step3(){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2);
}
void step4(){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(2);
}
void step5(){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(2);
}

void step6(){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
delay(2);
}
void step7(){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(2);
}
void step8(){
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(2);
}

Start by reading the sticky post at the top of this forum about how to properly post a question and your code using code tags. It helps people help you.

If you want your program to only run once, then put your code in the setup() function, not the loop() function.

Or, at the end of the loop add

while(1);

and the program will endlessly cycle there until you reset it.

Among other issues, this does not look right:

  for(i=0;i<000;i++){
  clockwiserotate();}

000 is the same as 0. I don’t think that this for loop ever executes.

to properly functionalize (that is not a word btw) your sketch do something like this

void step(uint8_t pins){
  for (uint8_t i=0; i<4; i++) {
    digitalWrite(8+i, (pins & (1<<i)));
  }
  delay(2);
}

now you can call step(B1001); // example for step 8
or declare an Array to hold those values firstconst uint8_t steps[]={B0001,B0011,B0010,B0110,B0100,B1100,B1000,B1001};
and then call step from a loop

void counterclockwiserotate() { //revolve counterclockwise
  for (uint8_t i=0; i<8; i++) {
    step(steps[7-i]);
  }
}

of course there are other ways still to generate the pin states other than using an array it being a linear pattern.

n.b. code untested may contain typos.

If the bottom half is exactly the same as the top half, you can delete the bottom half.
Also, you can't have 2 setups or loops.

ps.
you don't have to, but I put my functions outside of the setup and loop.

awesome_tornado:
ps.
you don't have to, but I put my functions outside of the setup and loop.

You do have to.

If you are driving a stepper motor you can greatly simplify your code by using one of the existing stepper libraries, like the built-in one.

#include <Stepper.h>


const int StepsPerRevolution = 512;


Stepper stepper(StepsPerRevolution, 8, 9, 10, 11);


void setup()
{
  //revolve three revolutions clockwise
  stepper.step(StepsPerRevolution * 3);


  delay(100);              // wait for a second
  delay(1100);              // wait for a second
}


void loop() {}