[Help pls] How to stop looping in button A when press button B

I am doing a timer with two simple function -
(1) When press button A, plus 1
(2) When press button B, minus 1 until 0

I’ve worked out the following code but not work for (2). Could someone help me, please?

input.onButtonPressed(Button.A, function () {
while (true) {
Time = Time + 1
basic.showNumber(Time)
basic.pause(10)
basic.clearScreen()
}
})

input.onButtonPressed(Button.B, function () {
while (Time > 0) {
Time = Time - 1
basic.showNumber(Time)
basic.pause(10)
basic.clearScreen()
}
})

Hi

is this what you wanted?

input.onButtonPressed(Button.B, function () {
    Count = -1
})
input.onButtonPressed(Button.A, function () {
    Count = 1
})
let Count = 0
Count = 0
let Time = 0
basic.forever(function () {
    Time = Time + Count
    if (Time > -1) {
        basic.showNumber(Time)
        basic.pause(10)
        basic.clearScreen()
    } else {
        basic.clearScreen()
    }
})

you could try on button released