# Optimizing code for SPEED / STABILITY, ways to write, stepper example

**URL:** <https://forum.arduino.cc/t/optimizing-code-for-speed-stability-ways-to-write-stepper-example/1300732>\
**Category:** Programming\
**Created:** [September 11, 2024, 8:14pm UTC](https://forum.arduino.cc/t/optimizing-code-for-speed-stability-ways-to-write-stepper-example/1300732 "2024-09-11T20:14:53Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [September 12, 2024, 1:03pm UTC](https://forum.arduino.cc/t/optimizing-code-for-speed-stability-ways-to-write-stepper-example/1300732/10 "2024-09-12T13:03:18Z")

</div>

> [@0212995500229](#):
>
> Alot of times I have trouble with "if logic" when there is alot of things to take in account , something in that style:  
> "if this and this, but not this, do this, but also if you do this then dont do this, but also do this if first 3 things are ok" and it goes on and on.

The [switch-case](https://www.arduino.cc/reference/en/language/structure/control-structure/switchcase/) structure, commonly used in [FiniteStateMachines](https://forum.arduino.cc/t/yet-another-finite-state-machine-introduction/1198997) is a good alternative to of complicated nests of if statements.

Have you seen these:

> [@Best first 5 topics to read to reach Trust Level 1?](https://forum.arduino.cc/t/best-first-5-topics-to-read-to-reach-trust-level-1/1287592/1):
>
> - [Planning and Implementing an Arduino Program](https://forum.arduino.cc/t/planning-and-implementing-an-arduino-program/252364/2) by @Robin2-- A great way to plan your program to be flexible, easy to read, understand, maintain, and extend. ( Live Sim: [Lesson A](https://wokwi.com/projects/407398005837428737) ... [Lesson G](https://wokwi.com/projects/407397568486835201) )
> - [Demonstration code for several things at the same time](https://forum.arduino.cc/t/demonstration-code-for-several-things-at-the-same-time/217158) by @Robin2-- An example running a couple blinking LEDS, a button and two servos, all independently. ([Live Simulation](https://wokwi.com/projects/366664987128970241))

---

_[View the full topic](https://forum.arduino.cc/t/optimizing-code-for-speed-stability-ways-to-write-stepper-example/1300732)._
