continue statement not within a loop error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PlzSendHelp
    New Member
    • May 2019
    • 3

    #1

    continue statement not within a loop error

    I'm a student and I'm not sure why I'm getting this error.
    Code:
    // Using Arduino Uno and RFIDs RC522
    #include <require_cpp11.h>
    #include <MFRC522.h>
    #include <deprecated.h>
    #include <MFRC522Extended.h>
    
    #include <SPI.h>
    #include <MFRC522.h>
    #define SS_PIN 10
    #define RST_PIN 9
    
    MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
    
    char count = '0'; 
    int greenLED = 6;
    int redLED = 7;
    int orangeLED = 8;
    
    
    void setup()
    {
    pinMode(greenLED, OUTPUT);
    pinMode(redLED, OUTPUT);
    pinMode(orangeLED, OUTPUT);
    
    Serial.begin(9600); // Initiate a serial communication
    SPI.begin(); // Initiate SPI bus
    mfrc522.PCD_Init(); // Initiate MFRC522
    Serial.println("Approximate your card to the reader...");
    Serial.println();
    }
    
    void loop()
    {
    // Look for new cards
    if (true)(!mfrc522.PICC_IsNewCardPresent()); {
    continue; 
    
    }
    // Select one of the cards
    if (true) (!mfrc522.PICC_ReadCardSerial()); {
    continue; 
    
    }
    
    // Show UID on serial monitor
    Serial.print("UID tag :");
    String content = "";
    byte letter;
    for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    Serial.println();
    content.toUpperCase();
    int count = 0;
    if (content.substring(1) == "89 E7 75 47") 
    {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(orangeLED, HIGH);
    delay(1000);
    digitalWrite(orangeLED, LOW);
    
    count = count + 1; 
    }
    else {
    Serial.println(" Access denied");
    Serial.println();
    digitalWrite(redLED, HIGH);
    delay(1000);
    digitalWrite(redLED, LOW);
    }
    
    if (content.substring(1) == "F9 9A 76 47") {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(orangeLED, HIGH);
    delay(1000);
    digitalWrite(orangeLED, LOW);
    count = count + 1;
    }
    else {
    Serial.println(" Access denied");
    Serial.println();
    digitalWrite(redLED, HIGH);
    delay(1000);
    digitalWrite(redLED, LOW);
    }
    
    if (count == 2) { 
    digitalWrite(greenLED, HIGH);
    delay(3000);
    digitalWrite(greenLED, LOW);
    }
    }
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    continue statement is used inside a loop body to jump to the next iteration.

    Here, you are using the continue statement inside the body of an if statement and there is no loop around. You have to use loops (for, while & do-while) in order to use continue.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      I'm not familiar with the layout of the if statements on lines 36 and 41. These statements would be illegal in C; naybe this is something C++ allows.

      As dev7060 points out, the continue statements on lines 37 and 42 are illegal. What do you want them to accomplish?

      Comment

      • PlzSendHelp
        New Member
        • May 2019
        • 3

        #4
        I want to scan two separate RFIDs while the code is running the continues were originally returns but I thought that was why it wasn't letting me scan two RFIDs. I think it may be something else, I'm still not sure how to stop the program in the middle to let me scan the second RFID?

        Comment

        • dev7060
          Recognized Expert Contributor
          • Mar 2017
          • 656

          #5
          I am not familiar with Arduino programming. But here are the few things I observed.

          Lines 36 and 41 seem bit odd to me. Semicolons are used just after the if conditions, which literally means that ifs have no body.

          Also, in the same lines, there are some functions calling. These should be present in the if body (wrapped under curly braces) rather than simple brackets. If the functions are returning values and used as conditions (as I noticed IsNewCardPresen t(), may return a value, true or false), in this case, when two or more conditions are present,they are combined using logical operators (like logical AND or logical OR) under a single bracket set, not in the separate ones.


          As you mentioned, the continues were originally returns, it seems unclear about the goal in using continue statement here. Continue statement cannot be used without any loop. By loop, I mean loops like for, while or do-while, not a function named loop (as written in the program).

          A good read on the use of Continue here.

          Comment

          Working...