ERROR:Expected unqualified-id before 'for'

Hi All;
I am Atul. I've been working on this error for about 2 hours, could't figure it out . Hope you can help me.

#include <SPI.h>
#include <MFRC522.h>
////////////////////////////////////////////oled//////////////////////////////////////////
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /reset=/ U8X8_PIN_NONE);
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 7); // RX, TX
#define RST_PIN 10 // Configurable, see typical pin layout above
#define SS_PIN 8 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRCS22 instance
///////////////////////////////////////////////////////////

void setup() {
Serial.begin(9600);
mySerial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRCS22 card
Serial.println(F("Read personal data on a HIFARE PICC:"));
////////////////////////////////////////////////oled//////////
u8g2.begin();
u8g2.enableUTF8Print();
pinMode(4,1);
digitalWrite(4,1);
//////////////////////////////////////////////////////////////
//shows in serial that it is ready to read
}
for (uint8_t i = 0; i < 16 ; i++)
{
////////////////////////////////
String str((char*) buffer2);

u8g2.firstPage();
do{
u8g2.setFont(u8g2_font_open_iconic_all_2x_t);
u8g2.drawGlyph(25, 18, 120);
u8g2.drawGlyph(55, 18, 228);
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setCursor(0,50);
u8g2.print("Attendance marked ");
u8g2.setCursor(0.30);
u8g2.println(str);
}
while ( u8g2.nextPage() );
Serial.write(buffer2 );
mySeria1.println(str);
}
//showy in serial that it is ready to read
Thanks in advance :slight_smile: :slight_smile:

The for loop appears to be outside of a function

Installation & Troubleshooting -
For problems with Arduino itself, NOT your project

Please remember to use code tags when posting code