67873

How to get out this Do-While loop?

<h3>Question</h3>

I've this basic Arduino code, and I want to have <em>2 options to exit this Do-While loop</em>. I simplified my original code to highlight the real problem: the Do-While <em>doesn't recognize the OR || condition to exit the loop</em>

In this code I'm starting with two integer variables that are equal to zero and as soon as they enter the Do-While, they'will be setted equal to 2 both, so that they can immediately exit the Do-While in the first iteration.

Here's my code:

int fin = 0; int ending = 0; int counter = 0; void setup() { Serial.begin(9600); }; //void setup void loop () { do { Serial.println("We are IN Do-While #1"); ending = 2; //fin = 2; } while ((ending < 1) || (fin < 1)); //I have just one condition for exit the Do-While ending = 1 Serial.println("We are OUT Do-While #1"); delay(3000); do { counter++; } while(counter<=100); Serial.println("We are OUT Do-While #2"); delay(3000); }

My problem is that I'm not setting <em>fin = 2</em>, because I want to test if the OR condition is working.

But it seems that it can't exit the Do-While unless they're both equal to 2. This is strange to me because the OR condition allows to exit the Do-While with a double options, in this particular case these options are:

<em>ending<1</em> OR (the alternative option).. <em>fin<1</em>

Additionally if I change (the rest of the code is the same) the while condition with an AND it behave like I want: so that I have two ways to exit the Do-While loop.

Recommend

  • What are these routing styles called in a web application?
  • Load data only from test/resources while testing with Spring Boot
  • Passing struct members to function in c
  • Showing MYSQL table columns with key types and reference
  • Is there a way to assign a multi-line string to a object property?
  • Svg click events not working properly
  • Repeated activity initializations and memory usage
  • Using blurred background in view with the storyboard in iOS
  • Is there a Python library to list primes?
  • Wordpress PHP within PHP
  • How to deploy a COM
  • Taxonomy is not working
  • How to warn user not to leave the page? [duplicate]
  • Access VBA lookup folder and create if does not exist DLOOKUP
  • Counting the Words in a String [closed]
  • Forward slash vs backward slash for file path in git bash
  • How do methods within a class access class constant variables?
  • How to smoothly connect two signals in matlab [closed]
  • Converting bitmap to byte and vice versa
  • Corda: How to implement hierarchical relationships between state data persisted to H2
  • Tkinter tkMessageBox disables Tkinter key bindings
  • Auto send email based on the time and email address in database
  • Defer unused CSS
  • Query regarding com.jcraft.jsch.JSchException: UnknownHostKey: x.y.com. DSA key fingerprint is “ac:e
  • What are advantages/disadvantages of using Selenium for Java vs .NET applications?
  • Spotify cocoalibspotify offline status set to 1 but all tracks stuck at waiting
  • Add checkbox dynamically using angular 2
  • readmore button or show/hide for php
  • Ajax call on Multiple selection in Select box
  • reshape/remould data frame to create normalized bar chart and pie chart
  • ssh remote server login script
  • How to use FirstOrDefault inside Include
  • PHP Permalinks.. how to change?
  • Spring Boot not autowiring @Repository
  • Running R's aov() mixed effects model from Python using rpy2
  • ReferenceError: TextEncoder is not defined
  • ARKit code issue {unknown error -1=ffffffffffffffff error: Task failed with exit 1}