If/else statement not evaluating

I’m trying to automate the maze search I’ve created (I know I keep posting about this one). So weird issue, I need to test if the paths have been explored so I created a variable that can be updated every time there is no unvisited neighbor, however I got stuck for a while here as I simply put the path_evaluated counter in the else statement, which would cause it to run endlessly and therefore “detect” the procedure was finished prematurely, It wasn’t until I specifically created a (!next) statement that it was able to correctly identify the number of paths it had evaluated. Again this is probably a noobish question but I thought that else was only supposed to run if the original statement was false.

function findnode(){

  if(nodes_array_Created&&!paths_completed){
    var counts = nodesindex.length;

    while(ad<counts){
      total_paths += nodesindex[ad].neighbours.length;
      ad++;
    }

for(var i=0;i<nodesindex.length;i++){

    var a = key_Node[i].original_id.toString();
    var b = key_Node[i].original_id;
    nodesindex[i].connectedNodes[b] = true;
    var next = nodesindex[i].neighbour_Node(b);

    var steps_to_nodes = key_Node[i].steps_to_nodes;
    find_node_count ++;
    if(key_Node[i].nodes<key_Node[i].neighbours.length){

    if(next){
      nodesindex[i].highlight();

      if(next.node){
        next.connectedNodes[b]=true;
        var a = nodesindex[i].parent[0]
        var b = nodesindex[i].parent[1]
        if(a === key_Node[i]){
          var node_info = [];
          for(var j=0;j<key_Node[i].node_info.length;j++){
            if(!key_Node[i].node_info[j][0]&&node_info.length<1){
            node_info = key_Node[i].node_info[j];
                      }}
            if(node_info.length>0){
            node_info[0] = steps_to_nodes;
            node_info[1] = next;
          }
        }
        else if(b === key_Node[i]){
          var node_info = [];
          for(var j=0;j<key_Node[i].node_info.length;j++){
            if(!key_Node[i].node_info[j][0]&&node_info.length<1){
            node_info = key_Node[i].node_info[j];
                      }}
            if(node_info.length>0){
            node_info[0] = steps_to_nodes;
            node_info[1] = next;
          }
        }
        if(nodesindex[i].node){
          var node_info= [];
          for(var j=0;j<next.node_info.length;j++){
            if(!key_Node[i].node_info[j][0]&&node_info.length<1){
            node_info = key_Node[i].node_info[j];
                      }}
            if(node_info.length>0){
            node_info[0] = steps_to_nodes;
            node_info[1] = next;
          }
        }
        key_Node[i].steps_to_nodes = 1;
        nodesindex[i] = key_Node[i];
        key_Node[i].nodes ++;
        //paths_evaluated ++;
    }
      else{
        key_Node[i].steps_to_nodes ++;

      if(!next.node_info[0][1] ){
      next.node_info[0][0] = steps_to_nodes;
      next.node_info[0][1] = key_Node[i];
      }
      else{
        next.node_info[1][0] = steps_to_nodes;
        next.node_info[1][1] = key_Node[i];
      }
      key_Node[i].child.push([steps_to_nodes,next]);
      nodesindex[i] = next;

    }
      }
        else {
      nodesindex[i] = key_Node[i];
      if(count>0){
        key_Node[i].steps_to_nodes = 1;
      }}

      if(!next){
        paths_evaluated++;
      }
    }
    else if(!key_Node[i].evaluated){
      key_Node[i].evaluated = true;
      //paths_evaluated ++;
    }

    }
    console.log(testing)
    for(var i=0;i<key_Node.length;i++){
      var c = key_Node[i].original_id;
        //nodesindex[i].connectedNodes[b] = true;
      var nextKey = key_Node[i].neighbour_Node(c);
      if(!next){
        //paths_evaluated ++;
      }
    }
  }
};

your if else code is so complex, that it is very difficult to follow
esp. if you catch all the possibilities…

you could start with a diagnostic print statement in each section,
so in console you can follow the logic.

var diagp = false;
/...
  if (diagp) print("i "+i);
//...

function keyPressed() {
 if ( key == 'p' ) diagp = ! diagp; 
}

thanks, I shall give this a try. I’m not sure if it can be simplified, given what I want to achieve, but I shall diagnose this.

Hey There!

Maybe each thing in the if statement should have their own method. So you can just take out a method and get an easy get to what can be causing the issue ?