samedi 2 mai 2020

Monitor variable in a loop with VSCode debugger

I want to monitor values of num and ctrl while this little code is executing, but I hate blemishing it with print statements. I have tried placing break point at the start of the loop, placing num on the watch and then continuing the debug process, but it displayed num: *not available*. Placing break point at the end or not placing it at all both resulted in similar outcome.

Placing break point at the if statement resulted in me having to press continue button every time the loop reached the statement, which I deemed implausible.

Any suggestion would be welcome.

num = 0
while True:
    num += 1
    ctrl = 0
    for i in range(1, num + 1):
        if num % i == 0:
            ctrl += 1
    if ctrl == 500:
        print(num)
        break

Aucun commentaire:

Enregistrer un commentaire