Can An Else If Statement Return To Run An If Statement? - Arduino Forum Home » Arduino If Statement Return » Can An Else If Statement Return To Run An If Statement? - Arduino Forum Maybe your like Arduino If Then Multiple Conditions Arduino If Two Conditions Arduino Inventor's Guide Pdf Arduino Inverter 12v 220v Arduino Inverter Control Can an Else If statement return to run an If statement? Projects Programming JeffHill987 June 11, 2017, 1:32am 1 Hello everybody, I'm new to Arduino, and I have a relatively simple question to ask. It is possible for an else if statement to return and run the original if statement code upon completion? Here is my code: #include <IRremote.h> #include <MotorLibrary.h> MotorLibrary motorLibrary; int RECV_PIN = 2; //define input pin on Arduino IRrecv irrecv(RECV_PIN); decode_results results; #include <Ultrasonic.h> int PIEZOPin = 9; // Pin used for the PIEZO Speaker int maximumRange = 45; // Maximum range needed int minimumRange = 0; // Minimum range needed Ultrasonic ultrasonic(5, 6); // (Trig PIN,Echo PIN) void setup() { pinMode(PIEZOPin, OUTPUT);// Use Piezo (if required) Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver motorLibrary.debugMotors(true); } void loop() { long distance = ultrasonic.Ranging(CM); // CM or INC //Serial.print("Object distance (in cm's) = "); if (results.actualKey == "*") { motorLibrary.forward(255); } else if (distance <= maximumRange) { motorLibrary.stopMotors(); } irrecv.resume(); // Receive the next value } Basically, I want my tank to detect and object, avoid it, and then continue on. I've tried using while statements and the like to no avail, so I'm back to where I have started. Any help is greatly appreciated jremington June 11, 2017, 1:47am 2 The loop() function loops, very rapidly. All you need to do is, somewhere in the loop function, execute a single if block: if (object_detected) { do_avoid_object(); object_detected = false; //may not be needed } The program will continue on until the end of the loop() function and loop() will be called again, to start over. JeffHill987 June 11, 2017, 1:51am 3 jremington: The loop() function loops, very rapidly. All you need to do is, somewhere in the loop function, execute a single if block: if (object_detected) { do_avoid_object(); object_detected = false; //may not be needed } The program will continue on until the end of the loop() function and loop() will be called again, to start over. Thanks for the reply! I'll try it out now Related topics Topic Replies Views Activity returning from a statement Programming 16 5875 May 5, 2021 "if" question Programming 4 1046 May 5, 2021 i have trouble, after if condition is true but not back to void loop() ?? Programming 3 688 May 5, 2021 Entering 'else if' statement when it should not meet the condition to enter it. Programming 5 1104 May 5, 2021 How can I stop my else if statement from running straight after my first if Programming 3 622 May 5, 2021 Tag » Arduino If Statement Return Return - Arduino Reference If/else And Return Question - Arduino Forum If - Arduino Reference How To Return A Value From A Void Function And Use It Inside The Void ... Using Functions In A Sketch | Arduino Documentation Return - Référence Arduino Returning A Value From A Function | Arduino Programming Part 16 Goto And Return Statements In Arduino - Electronics Fun Arduino If Statement - JavaTpoint Return | Référence Du Langage Arduino En Français Functions With Arduino - Packt Arduino Coding - Writing Functions - 4 Examples Arduino IF Statement Code Examples Arduino Return Array From Function - Delft Stack