# Need help understanding why code works only a certain way

**URL:** <https://forum.arduino.cc/t/need-help-understanding-why-code-works-only-a-certain-way/1057346>\
**Category:** Programming\
**Created:** [November 23, 2022, 11:56pm UTC](https://forum.arduino.cc/t/need-help-understanding-why-code-works-only-a-certain-way/1057346 "2022-11-23T23:56:18Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [November 26, 2022, 9:44am UTC](https://forum.arduino.cc/t/need-help-understanding-why-code-works-only-a-certain-way/1057346/9 "2022-11-26T09:44:12Z")

</div>

> [@frost\_10](#):
>
> However, I can still use delay in a more localised fashion? Say I make a couple of if nested statements and at the end of the last if statement I say delay(). That wouldn't mess with any millis outside of that localised function, right?

As you are yet not so experienced you should not mix-up delay() and millis().

Understanding non-blocking timing and how to avoid each and every delay() requires more than just looking at the classical blink without delay-demo-code.

**After** having understood the real nature of non-blocking coding you wil RE-recognise the principle inside the blink-without-delay-example. In short "BWD"

But IMHO only looking at the BWD-example makes it hard to understand the fundamental difference between delay-ing and non-blocking-coding.

It is not just a matter of 20 minutes playing around with the BWD-example.  
Depending on your talent and how long you want to learn on it per day  
it is realistic to estimate learning the basics of non-blocking coding will take some hours or maybe some days.

Me myself I haven't found a textbased online tutorial that would explain it all in a way that  
with judging with my personal criteria I would say "very well explained"

Some parts are epxlained in two tutorials I have written.

This is about non-blocking timing

> [@Example-code for timing based on millis() easier to understand through the use of example-numbers / avoiding delay()](https://forum.arduino.cc/t/example-code-for-timing-based-on-millis-easier-to-understand-through-the-use-of-example-numbers-avoiding-delay/974017):
>
> non-blocking timing. Execute code only from time to time. There are a lot of different ways to learn programming. This thread wants to add another approach that is different to the yet existing ones. UPDATE 06.01.2023 if you are mainly interested in applying non-blocking timing you can do a quick read of this short tutorial / demonstration If you are intersted in understanding the details how it works go on reading here. I use an everyday analogon in this post to explain the basic principle …

This is about state-machines (written by me though not in the quality that I myself would say all details explained in sufficient deepness)

> [@A Demo-Code explaining the switch-case state-machine and how to do things (almost) in parallel](https://forum.arduino.cc/t/a-demo-code-explaining-the-switch-case-state-machine-and-how-to-do-things-almost-in-parallel/888172):
>
> Hi everybody, if you look at the end of this first posting you see a list of links that show where this tutorial was used as a link. Go through this list to find additional information on how to apply this code This democode requires only the pure microcontroller without any hardware. You just open the serial monitor to watch the behaviour of the code. From time to time I enjoy writing demo-codes that want to explain programming-functionalities. There are a lot of different approachs to expl…

I have some ideas how to give the overview about non-blocking-coding = multitasking without an RTOS but not yet written.

best regards Stefan

---

_[View the full topic](https://forum.arduino.cc/t/need-help-understanding-why-code-works-only-a-certain-way/1057346)._
