473,480 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

continue statement not within a loop error

3 New Member
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.  
May 7 '19 #1
4 8731
dev7060
639 Recognized Expert Contributor
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.
May 7 '19 #2
donbock
2,426 Recognized Expert Top Contributor
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?
May 8 '19 #3
PlzSendHelp
3 New Member
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?
May 9 '19 #4
dev7060
639 Recognized Expert Contributor
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.
May 10 '19 #5

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

Similar topics

15
9126
by: PagCal | last post by:
Is this language missing the functionality of a C/C++ 'continue' statement? For example: While NOT isEof() If condition ' a C or C++ continue would work here ' but we are forced to use a...
1
1373
by: SJ | last post by:
I'm developing a WAP client which presently works fine on most mobile phone browsers, but gives me an Infinite loop error (error 1025) when i try to access it from a couple of phones(motorola for...
1
1919
by: alisbub | last post by:
DOes anyone know how to get the answer to this?? Please Help me. A simple way to to test the effect of a continue statement in the body of a for loop. What is printed? for (putchar( ' 1 ' );...
5
38077
by: AnDyG | last post by:
Hi everyone, i have a php script that echoes the following code from an if statement, what i need to do is make part of this only show if ($cat=="fireplaces.php"). Does anybody have any...
5
2750
by: Poly | last post by:
Here is a block of code that I am having trouble with. I rewrote it as a main function, so I could isolate the problem to fix it, but still haven't been able to figure out the problem. I am pretty...
2
21001
by: ianmcdonagh | last post by:
Hi folks, I'm looking to pick everyone's brains. I have a cursor, with over 200 columns in the select. I am using a case in one of the columns which I'm retrieving, and want to issue an...
2
2239
Prakash Gnana
by: Prakash Gnana | last post by:
Can i use break(); and continue(); statement inside if loop?
3
12176
by: Paulo Santos | last post by:
First of all, it's my first time here. Also, i'm working on a simple rent management program for a school project. I've fixed most of the errors but i'm lost on what could be wrong here: error:...
1
1449
by: c0d3rX | last post by:
Does anyone have any good coding examples which use a continue statement. I'm fairly new to C programming and am unfamiliar with continue statements.
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.