Arduino Skipping if else statement inside while loop

Hi there, my arduino seems to be skipping part of the code and immediately looping the void setup() function. i am not sure why it is skipping the if else statement inside the while loop...

this is my code :

#include <SPI.h>
#include <WiFi.h>
#include <GSM.h>

#define PINNUMBER ""
#define GPRS_APN       "sunsurf" // replace with your GPRS APN
#define GPRS_LOGIN     "65"    // replace with your GPRS login
#define GPRS_PASSWORD  "user123" // replace with your GPRS password

char ssid[] = "john";  // wireless network name
//char password[] = ""; // wireless password
int status = WL_IDLE_STATUS;
WiFiClient client;
IPAddress server(192,168,1,100);
byte bssid[6];//for bssid aka AP Mac
byte mymac[6];
String bss; //string up the bssid
String mac;
String ap_mac = "ap_mac=";
String arduino_mac = "arduino_mac=";
String send_arduino_mac;
String send_ap_mac;
GSMClient GSMclient;
GPRS gprs;
GSM gsmAccess;
char GSMserver[] = "arduino.cc"; // the base URL
char GSMpath[] = "/latest"; // the path
int GSMport = 80; // the port, 80 for HTTP

void setup() {
  Serial.begin(9600);
  //Serial.println(WiFi.firmwareVersion());
  
  Serial.println("Starting Arduino web client");
  boolean notConnected = true;
  while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)){
        
      notConnected = false;
      Serial.println("Accepted");
      
        }
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
    
  }
}

and immediately looping the void setup() function.

It isn't skipping the if/else. It's resetting.

String bss; //string up the bssid
String mac;
String ap_mac = "ap_mac=";
String arduino_mac = "arduino_mac=";
String send_arduino_mac;
String send_ap_mac;

Useless waste of resources.

You are almost certainly running out of memory. Though it's hard to tell for certain, since you didn't post all of the code. Since we are keeping things from each other, I'll keep the rest of the answer to myself.

@chihao711

We cannot reproduce the problem if you do not post your complete code. ( loop is missing )

As PaulS correctly indicates (in his own style) the usage of the String class is depreciated as it uses dynamic memory which is almost a dead sin in the embedded world. After initializing you should never allocate dynamic memory as you end up with "Swiss cheese RAM".

IN case you do not know what dynamic memory is, please check wikipedia or this tutorial of Adafruit

Your if statement checks first one and you have one & and not && so there is one thing according to me and if either one of your checks should be use || instead.