# Restart loop

**URL:** <https://forum.arduino.cc/t/restart-loop/699980>\
**Category:** Programming\
**Created:** [March 12, 2021, 10:16pm UTC](https://forum.arduino.cc/t/restart-loop/699980 "2021-03-12T22:16:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![frodv](https://avatars.discourse-cdn.com/v4/letter/f/439d5e/32.png) [@frodv](https://forum.arduino.cc/u/frodv)\
**Post date:** [March 12, 2021, 10:16pm UTC](https://forum.arduino.cc/t/restart-loop/699980/1 "2021-03-12T22:16:47Z")

</div>

Hi, is there a way to start vold loop from begining in the middle of the loop if something happens?

For an example, the loop starts and loops as it should if a pin is set HIGH, but if the pin is LOW, the loop starts from the top and do the first bit of the loop until the pin is set HIGH again, then it runs the entire loop.

---

<div class="post-metadata">

**Author:** ![guix](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/guix/32/215371_2.png) [@guix](https://forum.arduino.cc/u/guix)\
**Post date:** [March 12, 2021, 10:19pm UTC](https://forum.arduino.cc/t/restart-loop/699980/2 "2021-03-12T22:19:05Z")

</div>

Hello,

Yes you can use return;

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [March 12, 2021, 10:22pm UTC](https://forum.arduino.cc/t/restart-loop/699980/3 "2021-03-12T22:22:47Z")

</div>

...or you could just skip to the end of loop()

---

<div class="post-metadata">

**Author:** ![frodv](https://avatars.discourse-cdn.com/v4/letter/f/439d5e/32.png) [@frodv](https://forum.arduino.cc/u/frodv)\
**Post date:** [March 12, 2021, 10:32pm UTC](https://forum.arduino.cc/t/restart-loop/699980/4 "2021-03-12T22:32:36Z")

</div>

How does return; work?

Can I use in an if () statement?

Like:

if (pin == LOW){  
return;  
}

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [March 12, 2021, 10:38pm UTC](https://forum.arduino.cc/t/restart-loop/699980/5 "2021-03-12T22:38:52Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [March 12, 2021, 10:55pm UTC](https://forum.arduino.cc/t/restart-loop/699980/6 "2021-03-12T22:55:59Z")

</div>

> How does return; work?

As you may guess from its name, return; causes the program to return to where the current function was called from. In this case loop() is called repeatedly from a hidden main() function, hence using return causes loop() to be called again from the start

---

<div class="post-metadata">

**Author:** ![frodv](https://avatars.discourse-cdn.com/v4/letter/f/439d5e/32.png) [@frodv](https://forum.arduino.cc/u/frodv)\
**Post date:** [March 12, 2021, 11:06pm UTC](https://forum.arduino.cc/t/restart-loop/699980/7 "2021-03-12T23:06:59Z")

</div>

So if I use the return; function in the middle of a loop, the second half of the loop will never run?

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [March 12, 2021, 11:13pm UTC](https://forum.arduino.cc/t/restart-loop/699980/8 "2021-03-12T23:13:13Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 10, 2021, 11:13pm UTC](https://forum.arduino.cc/t/restart-loop/699980/9 "2021-07-10T23:13:30Z")

</div>

Closed on July 10, 2021, 11:13pm UTC

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
