• I have a nested while construct to find a value found in a source array to be within a destination array. When found want to break out from both loops. But it throws an error on the break statement in the outer loop. Could this be an error or do I miss something?

    I am using Espruino 1v99 on a ESP2866

    Here is the code:

    var oWifi = require('Wifi');
    oWifi.scan(function(aAp) {
      aAp.sort(function(a, b) {
        var r = a.rssi === b.rssi ? 0 : (a.rssi < b.rssi ? 1 : -1);
        return r;
      });
      console.log(aAp);
      var i=0, k=0, foundMy=false;
      while (i<aAp.length) {
        foundMy = false;
        while (k<aMyAp.length) {
          if (aAp[i].ssid === aMyAp[i].ssid) {
            foundMy = true;
            break;
          }
          k++;
        }
        if (foundMy) {
          break;  <--- Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop
        }
        i++;
      }
      if (foundMy) {
        oWifi.connect(aMyAp[k].ssid, {password: aMyAp[k].pwd}, function(err) {
          if (err===null) {
             console.log('Connection success to:', aMyAp[k].ssid);
          }
        });
      } else {
        console.log('no Ap found');
      }
    });
    
About

Avatar for fanThomas @fanThomas started