in this piece of code value of i has increased , and i dont know why. in this i am calling getBlock which returns a promise and after that i call another getBlock to get the next block. but in between the value of i increases .
plz help
return new Promise(function(resolve, reject) {
self.getBlockHeight().then((height)=>{
let errorLog = [];
for(var i=0;i <height;i++){
self.validateBlock(i).then((valid)=>{
if(!valid){errorLog.push(i)}
})
self.getBlock(i).then((block)=>{ //here i is 0
console.log(i) //here i is 1
self.getBlock(i+1).then((previousblock)=>{
// console.log(i);
let blockHash = block.hash;
// console.log(block)
let previousBlockHash = previousblock.previousHash;
// console.log(previousblock);
if(!(blockHash == previousBlockHash)){
errorLog.push(i)
}
})
})
}
})
});
}