Coroutine isn't entering If statement c#

Hi guys, i’m new to coroutines and im trying to make a simple Ai, it is supposed to follow when in range and lay a trail of nodes and navigate back to start position when the player breaks the range. it gets into the idle IEnumerator but wont then enter the If statement.

using UnityEngine;
using System.Collections;

public class shogoth_follow : MonoBehaviour {
	public GameObject target;
	int range; 
	float lockPos = 0;
	bool follow;
	bool hasFollowed;
	float timer;
	bool timerActive;
	public GameObject[] path;
	Vector3 myPosition;
	public GameObject path_Node;
	float speed =  3.0f;
	private float startTime;
	Vector3 startRotation;

	void Start () 
	{
		target = GameObject.FindGameObjectWithTag ("Player");
		StartCoroutine("idle");
		range = 10;
		
	}

	IEnumerator idle()
	{

		if(Vector3.Distance(gameObject.transform.position,target.transform.position)< range)
		{
			Debug.Log ("seen");
			startRotation = transform.rotation.eulerAngles;
			follow = true;
			hasFollowed = true;

		}
		else if (Vector3.Distance(gameObject.transform.position,target.transform.position)> range)
		{
			follow = false;
			if (hasFollowed)
			{
				CancelInvoke();
				yield return StartCoroutine("backTrack");
				
				
			}
		}
		if (follow)
		{
			Debug.Log ("follow state");
			yield return StartCoroutine("chase");
			
		}
		yield return null;
	}

	void spawnNode () 
	{
		GameObject newNode = Instantiate (path_Node, transform.position, transform.rotation) as GameObject;
		newNode.name = "pathNode";
		Debug.Log ("path node spawned");

	}



	void FindPath()
	{
		int i;
		GameObject[] pathNodes = GameObject.FindGameObjectsWithTag("pathnode");
		path = new GameObject[pathNodes.Length];
		for (i = 0; i < pathNodes.Length; i ++)
		{
			path _= pathNodes*;*_

* }*
* }*

* GameObject closestPath (GameObject[] targets)*
* {*
* int i;*
* float closest = (path[0].transform.position - transform.position).sqrMagnitude;*
* int targetNumber = 0;*
* for (i = 1; i < targets.Length; i++)*
* {*
_ float currentDistance = (path*.transform.position - transform.position).sqrMagnitude;
if(currentDistance < closest)
{
closest = currentDistance;
targetNumber = i;
}
}
return path[targetNumber];
}*_

* IEnumerator backTrack()*
* {*
* int i;*
* GameObject moveTarget;*
* FindPath ();*
* for (i = 0; i < path.Length; i++)*
* {*
* myPosition = transform.position;*
* startTime = Time.time;*
* moveTarget = closestPath(path);*

_ float step = speed * Time.deltaTime;
* transform.position = Vector3.MoveTowards(transform.position, moveTarget.transform.position, step);*_

* Destroy(moveTarget);*
* transform.rotation = Quaternion.FromToRotation(transform.rotation.eulerAngles,startRotation);*
* }*
* yield return StartCoroutine (“idle”);*
* }*

* IEnumerator chase()*
* {*
* InvokeRepeating(“spawnNode”,0,3);*
* transform.LookAt(target.transform.position);*
* transform.rotation = Quaternion.Euler (lockPos,transform.rotation.eulerAngles.y ,lockPos);*
_ transform.Translate(Vector3.forward * Time.deltaTime4);
}*_

* void Update ()*
* {*

* }*
}

Hi, I think your problem is, that the Idle coroutine does only one iteration (nothing meets the conditions), therfore nothing is tested again (there is no loop in Idle() routine).

Note: Check the UNITYGEMS, there are articles about Coroutines, Finite State Machines, AI, … with examples.