```
conn.connect(function (err) {
        if (err) throw err;
        var prizeCode = generatePrizeCode();// this method return a 5-digit code
        var query = "SELECT * FROM user WHERE code = ? ";
        var values = [[prizeCode]];
        conn.query(query, [values], function (err, result) {
            if (err) throw err;
            // Here I want to re-execute the above query if the result is not empty 
        });
    });

```

In the above code, I want to execute query as long as the result contain data. But I cannot use the loop like following pseucode, 

```
// if the result is empty, the generated code does not exist in database. So it can be used.
while(result.length != 0){
    var result = conn.query("SELECT * FROM user WHERE code = abc");
}

```

How can I achieve this?