user79627: I'll start off by saying I'm very very new to coding, so please bare with me.
I'm doing an assignment where the task is to create a traffic light system, but blocking delays aren't allowed. I have looked into "blink without delay", but it seems that option would require me to create far too confusing and long code than is needed. So instead I used for, else and goto functions together since it was a lot simpler and cleaner, but I have heard goto isn't a preferred option,
for(int i = 0; i < 20; i = i + 1)
{
    break0:
    digitalWrite(Traffic_R, HIGH);
    long int CurrentMillis1 = millis();
    
    break1:
    if (millis() - CurrentMillis1 <= 250){
        digitalWrite(Pedestrian_R, HIGH);
        goto break1;
    }else{
        long int CurrentMillis2 = millis();
        
        break2:
        if (millis() - CurrentMillis2 <= 250){
            digitalWrite(Pedestrian_R, LOW);
            goto break2;
        }
    }
}

Then I made another way without goto function,
for(int Test1 = millis(); Test1 < 7500; Test1 + millis())
{
  digitalWrite(LED, HIGH);
}

TLDR
So my question is, are either of these methods a "blocking method", like delay is? Also what are the pros and cons of each method? Also I can upload the code for the first method if needed. Thanks heaps in advance!

user37622: Here I have a simple example of cycling over 3 LEDs with the same 'delay' for every LED.
void loop() {

  static unsigned long previousMillis;
  static uint8_t cycleCounter;

  if (millis() - previousMillis > 100) {
    previousMillis = millis();
    digitalWrite(LEDS_CENTRAL_PIN, cycleCounter == 0);
    digitalWrite(LEDS_LEFT_PIN, cycleCounter == 1);
    digitalWrite(LEDS_RIGHT_PIN, cycleCounter == 2);
    cycleCounter++;
    if (cycleCounter == 3) {
      cycleCounter = 0;
    }
  }
}


user10794: break1: 
if (something) 
  goto break1; 

is basically a while loop - just more confusing to read.


Also I can upload the code for the first method if needed.

You can upload it, of course. Personally I would mark you down for using goto.


are either of these methods a "blocking method", like delay is?

Neither method literally blocks. The delay function blocks because it doesn't return until the time is up. Your loops don't block because you could conceivably do something else in the loop.


I have heard goto isn't a preferred option

For a good reason. Do you think that, if you looked at your code again in a year, you would easily understand it? I have been coding for years and would have to carefully follow all the ways that the goto could jump around in unexpected ways.
At least with a while loop you have a well-defined start and end of the loop.

79627: <p>I'll start off by saying I'm very very new to coding, so please bare with me.</p>
<p>I'm doing an assignment where the task is to create a traffic light system, but blocking delays aren't allowed. I have looked into &quot;blink without delay&quot;, but it seems that option would require me to create far too confusing and long code than is needed. So instead I used for, else and goto functions together since it was a lot simpler and cleaner, but I have heard goto isn't a preferred option,</p>
<pre class="lang-cpp prettyprint-override"><code>for(int i = 0; i &lt; 20; i = i + 1)
{
    break0:
    digitalWrite(Traffic_R, HIGH);
    long int CurrentMillis1 = millis();
    
    break1:
    if (millis() - CurrentMillis1 &lt;= 250){
        digitalWrite(Pedestrian_R, HIGH);
        goto break1;
    }else{
        long int CurrentMillis2 = millis();
        
        break2:
        if (millis() - CurrentMillis2 &lt;= 250){
            digitalWrite(Pedestrian_R, LOW);
            goto break2;
        }
    }
}
</code></pre>
<p>Then I made another way without goto function,</p>
<pre><code>for(int Test1 = millis(); Test1 &lt; 7500; Test1 + millis())
{
  digitalWrite(LED, HIGH);
}
</code></pre>
<p><strong>TLDR</strong>
So my question is, are either of these methods a &quot;blocking method&quot;, like delay is? Also what are the pros and cons of each method? Also I can upload the code for the first method if needed. Thanks heaps in advance!</p>
 37622: <p>Here I have a simple example of cycling over 3 LEDs with the same 'delay' for every LED.</p>
<pre><code>void loop() {

  static unsigned long previousMillis;
  static uint8_t cycleCounter;

  if (millis() - previousMillis &gt; 100) {
    previousMillis = millis();
    digitalWrite(LEDS_CENTRAL_PIN, cycleCounter == 0);
    digitalWrite(LEDS_LEFT_PIN, cycleCounter == 1);
    digitalWrite(LEDS_RIGHT_PIN, cycleCounter == 2);
    cycleCounter++;
    if (cycleCounter == 3) {
      cycleCounter = 0;
    }
  }
}
</code></pre>
 10794: <pre><code>break1: 
if (something) 
  goto break1; 
</code></pre>
<p>is basically a while loop - just more confusing to read.</p>
<hr />
<blockquote>
<p>Also I can upload the code for the first method if needed.</p>
</blockquote>
<p>You can upload it, of course. Personally I would mark you down for using <code>goto</code>.</p>
<hr />
<blockquote>
<p>are either of these methods a &quot;blocking method&quot;, like delay is?</p>
</blockquote>
<p>Neither method literally blocks. The <code>delay</code> function blocks because it doesn't return until the time is up. Your loops don't block because you could conceivably do something else in the loop.</p>
<hr />
<blockquote>
<p>I have heard goto isn't a preferred option</p>
</blockquote>
<p>For a good reason. Do you think that, if you looked at your code again in a year, you would easily understand it? I have been coding for years and would have to carefully follow all the ways that the <code>goto</code> could jump around in unexpected ways.</p>
<p>At least with a <code>while</code> loop you have a well-defined start and end of the loop.</p>
