Skip to main content
Made it syntax highlight the code for better readability
Source Link
#include <M5Stack.h>  // only necessary for my board (M5Stack)

bool condition_while = true;
bool condition_loop = true;
int condition_if = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  while (condition_while) {
    if (condition_if == 0) {
      Serial.println("testcase #1: if path reached");
      condition_if = 1;
    }
    else if (condition_if == 1 ) {
        Serial.println("testcase #2: if else path reached");
        condition_if = 2;
      }
    else {
      Serial.println("testcase #3: else path reached");
      condition_while = false;
    }
   Serial.println("testcase #4: path reached inside while");
  }
 if (condition_loop) {
  Serial.println("testcase #5: path reached outside while");
  condition_loop = false;
 }
}
#include <M5Stack.h>  // only necessary for my board (M5Stack)
    
bool condition_while = true;
bool condition_loop = true;
int condition_if = 0;

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
}

void loop() {
   while (condition_while) {
       if (condition_if == 0) {
           Serial.println("testcase #1: if path reached");
           condition_if = 1;
       }
       else if (condition_if == 1 ) {
           Serial.println("testcase #2: if else path reached");
           condition_if = 2;
       }
       else {
           Serial.println("testcase #3: else path reached");
           condition_while = false;
       }
       Serial.println("testcase #4: path reached inside while");
   }
   if (condition_loop) {
       Serial.println("testcase #5: path reached outside while");
       condition_loop = false;
   }
}
#include <M5Stack.h>  // only necessary for my board (M5Stack)

bool condition_while = true;
bool condition_loop = true;
int condition_if = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  while (condition_while) {
    if (condition_if == 0) {
      Serial.println("testcase #1: if path reached");
      condition_if = 1;
    }
    else if (condition_if == 1 ) {
        Serial.println("testcase #2: if else path reached");
        condition_if = 2;
      }
    else {
      Serial.println("testcase #3: else path reached");
      condition_while = false;
    }
   Serial.println("testcase #4: path reached inside while");
  }
 if (condition_loop) {
  Serial.println("testcase #5: path reached outside while");
  condition_loop = false;
 }
}
#include <M5Stack.h>  // only necessary for my board (M5Stack)
    
bool condition_while = true;
bool condition_loop = true;
int condition_if = 0;

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
}

void loop() {
   while (condition_while) {
       if (condition_if == 0) {
           Serial.println("testcase #1: if path reached");
           condition_if = 1;
       }
       else if (condition_if == 1 ) {
           Serial.println("testcase #2: if else path reached");
           condition_if = 2;
       }
       else {
           Serial.println("testcase #3: else path reached");
           condition_while = false;
       }
       Serial.println("testcase #4: path reached inside while");
   }
   if (condition_loop) {
       Serial.println("testcase #5: path reached outside while");
       condition_loop = false;
   }
}
Source Link
RJPlog
  • 307
  • 2
  • 3
  • 10

Basically it works.

Here you find a little sketch to see how it works. Try to transfere it to your solution.

#include <M5Stack.h>  // only necessary for my board (M5Stack)

bool condition_while = true;
bool condition_loop = true;
int condition_if = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  while (condition_while) {
    if (condition_if == 0) {
      Serial.println("testcase #1: if path reached");
      condition_if = 1;
    }
    else if (condition_if == 1 ) {
        Serial.println("testcase #2: if else path reached");
        condition_if = 2;
      }
    else {
      Serial.println("testcase #3: else path reached");
      condition_while = false;
    }
   Serial.println("testcase #4: path reached inside while");
  }
 if (condition_loop) {
  Serial.println("testcase #5: path reached outside while");
  condition_loop = false;
 }
}

This is the output on COM3

enter image description here