By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

continue statement not within a loop error

P: 3
I'm a student and I'm not sure why I'm getting this error.
Expand|Select|Wrap|Line Numbers
  1. // Using Arduino Uno and RFIDs RC522
  2. #include <require_cpp11.h>
  3. #include <MFRC522.h>
  4. #include <deprecated.h>
  5. #include <MFRC522Extended.h>
  6.  
  7. #include <SPI.h>
  8. #include <MFRC522.h>
  9. #define SS_PIN 10
  10. #define RST_PIN 9
  11.  
  12. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
  13.  
  14. char count = '0'; 
  15. int greenLED = 6;
  16. int redLED = 7;
  17. int orangeLED = 8;
  18.  
  19.  
  20. void setup()
  21. {
  22. pinMode(greenLED, OUTPUT);
  23. pinMode(redLED, OUTPUT);
  24. pinMode(orangeLED, OUTPUT);
  25.  
  26. Serial.begin(9600); // Initiate a serial communication
  27. SPI.begin(); // Initiate SPI bus
  28. mfrc522.PCD_Init(); // Initiate MFRC522
  29. Serial.println("Approximate your card to the reader...");
  30. Serial.println();
  31. }
  32.  
  33. void loop()
  34. {
  35. // Look for new cards
  36. if (true)(!mfrc522.PICC_IsNewCardPresent()); {
  37. continue; 
  38.  
  39. }
  40. // Select one of the cards
  41. if (true) (!mfrc522.PICC_ReadCardSerial()); {
  42. continue; 
  43.  
  44. }
  45.  
  46. // Show UID on serial monitor
  47. Serial.print("UID tag :");
  48. String content = "";
  49. byte letter;
  50. for (byte i = 0; i < mfrc522.uid.size; i++) {
  51. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  52. Serial.print(mfrc522.uid.uidByte[i], HEX);
  53. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  54. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  55. }
  56. Serial.println();
  57. content.toUpperCase();
  58. int count = 0;
  59. if (content.substring(1) == "89 E7 75 47") 
  60. {
  61. Serial.println("Authorized access");
  62. Serial.println();
  63. digitalWrite(orangeLED, HIGH);
  64. delay(1000);
  65. digitalWrite(orangeLED, LOW);
  66.  
  67. count = count + 1; 
  68. }
  69. else {
  70. Serial.println(" Access denied");
  71. Serial.println();
  72. digitalWrite(redLED, HIGH);
  73. delay(1000);
  74. digitalWrite(redLED, LOW);
  75. }
  76.  
  77. if (content.substring(1) == "F9 9A 76 47") {
  78. Serial.println("Authorized access");
  79. Serial.println();
  80. digitalWrite(orangeLED, HIGH);
  81. delay(1000);
  82. digitalWrite(orangeLED, LOW);
  83. count = count + 1;
  84. }
  85. else {
  86. Serial.println(" Access denied");
  87. Serial.println();
  88. digitalWrite(redLED, HIGH);
  89. delay(1000);
  90. digitalWrite(redLED, LOW);
  91. }
  92.  
  93. if (count == 2) { 
  94. digitalWrite(greenLED, HIGH);
  95. delay(3000);
  96. digitalWrite(greenLED, LOW);
  97. }
  98. }
  99.  
2 Weeks Ago #1
Share this Question
Share on Google+
4 Replies


P: 60
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.
2 Weeks Ago #2

Expert 100+
P: 2,396
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?
2 Weeks Ago #3

P: 3
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?
2 Weeks Ago #4

P: 60
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 IsNewCardPresent(), 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.
2 Weeks Ago #5

Post your reply

Sign in to post your reply or Sign up for a free account.