I need help with my code for my school assignment

So I have been given an assignment on making an LED brighten then dim, my current code is this

int out13 = 13; // Used variable to store pin number
int out12 = 12; // Used variable to store pin number
int out11 = 11; // Used variable to store pin number
int i = 0; // Used variable to store data
void setup()
{

pinMode(out13, OUTPUT); // initialize digital pin 13 as an output
pinMode(out12, OUTPUT); // initialize digital pin 12 as an output
pinMode(out11, OUTPUT); // initialize digital pin 11 as an output
}

void loop()
{
{ : Bright
for (int i = 0; i <= 28; i++);
analogWrite(11 , i);
delay(50);
if (i = 28); goto Dim;
}
for (int i = 28; i >= 1; i--);
analogWrite(11 , i);
delay(50);
if (i == 1); {
goto Bright;
}
}

any help would be tremendously appreciated, thank you.

Look at the Fade example in the IDE (File->examples->basics->Fade) to learn how to fade an LED.

Hello
How shall we help?

The use of goto is discouraged in C++. Use functions instead.

Someone needs to start with basics of C++ language

Oh and please use code tags

Post your code in code tags. Read the forum guidelines to see how to properly post code.

Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.

int out13 = 13; // Used variable to store pin number
int out12 = 12; // Used variable to store pin number
int out11 = 11; // Used variable to store pin number
int i = 0; // Used variable to store data
void setup()
{

  pinMode(out13, OUTPUT); // initialize digital pin 13 as an output
  pinMode(out12, OUTPUT); // initialize digital pin 12 as an output
  pinMode(out11, OUTPUT); // initialize digital pin 11 as an output
}

void loop()
{
  {
    ////// This is an extra '{'
: Bright ///// This is not how you define a label in C++
    for (int i = 0; i <= 28; i++) ///// This will step through 29 values
      ; ////// This empty statement is the only thing inside your 'for'

    analogWrite(11, i);  ////// You forgot to use the name you defined for this pin

    delay(50);

    if (i = 28)  ////// The '=' operator is for assigining a value.  You want '==' for comparing.
      ; ////// Again, you put an empty statement as the only thing inside your 'if'

    goto Dim;
  }

  for (int i = 28; i >= 1; i--)
    ; ////// This empty statement is the only thing inside your 'for'
    
  analogWrite(11, i);  ////// You forgot to use the name you defined for this pin
  
  delay(50);
  
  if (i == 1)
    ;  ////// Again, you put an empty statement as the only thing inside your 'if'

  {
    goto Bright;
  }
}

Thank you to those who have replied, I have updated my code and it compiles but it does not work, any suggestions would be greatly appreciated.

int out13 = 13;  // Used variable to store pin number
int out12 = 12;  // Used variable to store pin number
int out11 = 11;  // Used variable to store pin number
int i = 0;       // Used variable to store data
void setup()
{

  pinMode(out13, OUTPUT); // initialize digital pin 13 as an output
  pinMode(out12, OUTPUT); // initialize digital pin 12 as an output
  pinMode(out11, OUTPUT); // initialize digital pin 11 as an output
}

void loop()
{
Bright:
  for (int i = 0; i <= 28; i++);
  analogWrite(out11 , i);
  delay(50);
  if (i == 28) {
    goto Dim;
  }
Dim:
  for (int i = 28; i >= 1; i--);
  analogWrite(out11 , i);
  delay(50);
  if (i == 1); {
    goto Bright;
  }
}

don't you want something like:

for (int i = 0; i <= 28; i++) { 
  // do line 1
  // do line 2
}

same old same old

Hello
Take some time and study the for() loop instruction.


Bright:
  for (int i = 0; i <= 28; i++);
  analogWrite(out11 , i);
  delay(50);
  if (i == 28) {
    goto Dim;
  }
Dim:

The for statement itself is correct, but the semicolon indicates the end of the for statement and it consequently does nothing. Normally there would either be a single line of code to execute before the semicolon, or several lines of code within curly braces (similar to how you later do the if statement). Presumably you intended for the analogWrite and delay to be within the for, if so, then the if statement is useless, because when the for statement is no longer <= 28, it will terminate and continue on with the next line of code, which in your case is labeled Dim.

goto statements are rarely used, and should be avoided unless absolutely necessary, because they generally make the code harder to understand. For your code, the goto's are absolutely unnecessary. Also, if i is not equal to 28, goto Dim will not be executed, but the code will continue with the next sequential line, which is Dim:, so you will end up there regardless of the value of i.