ESP32 microPython pass用法

ESP32 microPython的network部分,修改官方给出的例程出现了一个不理解的现象。
下面是代码

def do_connect():
    print("Connecting...")
    wlan.active(True)
    wl = Wlanlist(wlan.scan())
    if not wlan.isconnected():
        if(wl.show('SSID')):#自己写的函数,用于检查是否存在对应SSID的WiFi
            wlan.connect('SSID','wifimima')
            while not wlan.isconnected():
                pass
            print("Connected")#没有生效
            return 1
        else:
            print("connect to FISHGAN10 failed")
            return 0
        
    if wlan.isconnected():
        print("Connected")
        return 2
    else:
        return 3

#测试部分    
print(do_connect())

对应的输出结果:

img

可以看到,在下面这个语句后面的print和return没有被执行

 while not wlan.isconnected():
                pass

搜索资料得pass是用于占位,那么这个while not函数是用来保证connect函数完成后程序再往下运行。那连接成功后为什么后面的语句没有执行呢。

这是因为在这个while循环中,一直没有满足条件(wlan.isconnected()为False),所以一直在循环中,直到连接上网络才会满足条件退出循环,所以后面的print和return语句没有执行。