How to modify loop variable

Hi, I’m trying to modify the loop variable conditionally but unable to figure out how to do it. Some one please explain here is my code.

let array = [1,2,3,5];
let innerLoopVariable;

function no(a){
    if(a==="2"){
        innerLoopVariable = 0;
    }else{
        innerLoopVariable = array.length-1;
    }
}

// no(3);

for(let j=innerLoopVariable;j=array.length-1?j>=0:j<array.length;j=0?j++:j--){
    //Here I'm trying to modify j based on condition but j is setting to false or true;
}

= is assignment. == or === is comparison

This looks like a sure-fire way to create an infinite loop.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.