Help with writing a loop in postman tests

I have a request (you can use it):

GET https://eu-api.backendless.com/1877CC4D-B4EA-4E2D-FFCB-78A7EDACDE00/ACA31220-F45A-474C-94E0-AB0700926637/hive/Management/list/keys?filterPattern=*&pageSize=5&cursor=0

There is a test with a loop, which will be canceled if the server returns cursor = 0

pm.variables.set('cursorValue', pm.response.json().cursor);
let finalCursor = "0";
let cursor = pm.variables.get('cursorValue');

while (cursor !== finalCursor && cursor !== null && cursor !== undefined) {
    pm.sendRequest({
        url: pm.variables.get("API host") + "/" + pm.variables.get("APP ID") + "/" + pm.variables.get("REST API Key") + "/" + 'hive/Management/list/keys?filterPattern=*&cursor=' + cursor + "&" + 'pageSize=5',
        method: 'GET',
    }, function (err, res) {
        if (err) {
            console.log(err);
        } else {
            cursor = res.json().cursor;
            pm.globals.set('cursorValue', cursor);
            pm.test(`Cursor equals ${cursor}`, () => {
                pm.expect(cursor).to.eql(finalCursor);
            });
        }
    });
}

However, when I send a request, first of all, the postman completely freezes (only a restart helps). Secondly, the first request is sent with cursor=0, but the next ones are all sent with cursor=360, but after the second one the cursor value should be different. How to fix this? enter image description here

For example:
1 iteration: A request is sent with cursor=0;
response from the server "cursor": "360"
2 iteration: Request is sent with cursor=360
Response from the server "cursor": "86"
3 iteration: Request sent from cursor=86
Response from the server "cursor": "415"
4 iteration: Request is sent from cursor=415
Response from the server "cursor": "10"
5 iteration: Request sent from cursor=10
Response from the server "cursor": "0" 
The test is over

Please help in any way you can