problems with goto statements

Hello. first of all, here is the program:

code:
void loop(){

int SerieNumber = {1,1,1,1,1,1};
int SerieNumber_ = {1,1,1,1,1,1};

int Difficulty = analogRead(Pot) / 204.6 + 1; LedReset(); // This basically just generates a number between 1 and 6. so “Difficulty” is a number from 1 to 6

// This is just an LED display.
if (Difficulty > 0) {digitalWrite(Led[8], HIGH);}
if (Difficulty > 1) {digitalWrite(Led[7], HIGH); digitalWrite(Led[6], HIGH);}
if (Difficulty > 2) {digitalWrite(Led[4], HIGH);}
if (Difficulty > 3) {digitalWrite(Led[3], HIGH); digitalWrite(Led[5], HIGH);}
if (Difficulty > 4) {digitalWrite(Led[1], HIGH); digitalWrite(Led[2], HIGH);}
if (Difficulty > 5) {digitalWrite(Led[0], HIGH);}

if (digitalRead(Btn[0]) == HIGH){ LedReset(); delay(500);
SerieNumber_[0]=random(0, 4); if (Difficulty == 1){ goto Display; }
SerieNumber_[1]=random(0, 4); if (Difficulty == 1){ goto Display; }
SerieNumber_[2]=random(0, 4); if (Difficulty == 1){ goto Display; }
SerieNumber_[3]=random(0, 4); if (Difficulty == 1){ goto Display; }
SerieNumber_[4]=random(0, 4); if (Difficulty == 1){ goto Display; }
SerieNumber_[5]=random(0, 4); if (Difficulty == 1){ goto Display; }

Display:
for (int n = 1; n <= Difficulty ; n++){
if (SerieNumber_[n-1] == 0){LedDisplay_1();delay(300);}
if (SerieNumber_[n-1] == 1){LedDisplay_2();delay(300);}
if (SerieNumber_[n-1] == 2){LedDisplay_3();delay(300);}
if (SerieNumber_[n-1] == 3){LedDisplay_4();delay(300);}}

for (int n = 1; n <= Difficulty ; n++){
if (digitalRead(Btn[0]) == HIGH) {LedDisplay_1(); SerieNumber[n-1]=0; n++;}
if (digitalRead(Btn[2]) == HIGH) {LedDisplay_2(); SerieNumber[n-1]=1; n++;}
if (digitalRead(Btn[1]) == HIGH) {LedDisplay_3(); SerieNumber[n-1]=2; n++;}
if (digitalRead(Btn[3]) == HIGH) {LedDisplay_4(); SerieNumber[n-1]=3;}
else n–;}}}

ok so the problem is… i want SerieNumber_ to change depending on what the Difficulty number is. (1-6). if the difficulty is 1, then im only going to use Serie_Number[1]… if Difficulty is 4, then i want to use all SerieNumber_[1-4]

now i made those goto statements to skip, so that those numbers that wont be used, will not be changed. but they do get changed… does anyone know why?

Use ctrl T to format your code. Get rid of your colors. Hurry, get rid of the gotos before others see them. Post your code with [ code] tags. Use the # button.

Hello. first of all, here is the program:

Posted incorrectly with colors obscuring a lot of it, making it hard to read.

ok so the problem is... i want SerieNumber_[x] to change depending on what the Difficulty number is.

So, why are you always changing SerieNumber_[ 0 ]?

Using trailing underscores in variable names does not help the readability of your code.

There is NO reason to use a goto.

It isn't clear what you are doing but here is a guess at a possible direction:

  switch (Difficulty) {
    case 1:
      myran=0
      break;
    case 2:
      myRan= random(0, 1) 
      break;
    case 3:
      myRan= random(0, 2) 
      break;
    case 4:
      myRan= random(0, 3) 
      break;
etc.,
  }

Then use SerieNumber_[myRan]

In what way is this:-

if (digitalRead(Btn[0]) == HIGH){ LedReset(); delay(500);
    SerieNumber_[0]=random(0, 4); if (Difficulty == 1){ goto Display; }
    SerieNumber_[0]=random(0, 4);   if (Difficulty == 1){ goto Display; }
    SerieNumber_[0]=random(0, 4); if (Difficulty == 1){ goto Display; }
    SerieNumber_[0]=random(0, 4); if (Difficulty == 1){ goto Display; }
    SerieNumber_[0]=random(0, 4); if (Difficulty == 1){ goto Display; }
    SerieNumber_[0]=random(0, 4); if (Difficulty == 1){ goto Display; } 
   
Display:
  for (int n = 1; n <= Difficulty ; n++){

not this?

if (digitalRead(Btn[0]) == HIGH){ LedReset(); delay(500);
    SerieNumber_[0]=random(0, 4); 
   
  for (int n = 1; n <= Difficulty ; n++){

They both do exactly the same thing.

Never ever ever never use ‘goto’ it just shows that you haven’t got a clue as to what you are doing. It is not needed.

Please help us understand your code by putting each { and } on separate lines with matching pairs indented by the same amount and the lines between then indented one extra level.

Can you explain what effect the difficulty level is intended to have on your code? At the moment I can’t guess.

omg i used copy paste... edited it now

finalbarrage: omg i used copy paste... edited it now

I don't see any improvement.

Still no code tags, and still the colours. Please read the how to use the forum sticky. Then try and explain what you are trying to do, because I am sure you are not doing it.