Question: I'm trying to figure out how to make a python program that highlights the position/positions of a certain inputed word in a sentence and lists what place that word is. For example if the sentence was: "The fat cat sat on the mat"
then the position for the word fat would be Number 2.

Heres what Ive got so far:

```
varSentence = ("The fat cat sat on the mat")

print (varSentence)

varWord = input("Enter word ")

varSplit = varSentence.split()

if varWord in varSplit:
    print ("Found word")
else:
    print ("Word not found")

```

Answer: 
The reason is that the iterator block is always lazy. Unless you call `GetEnumerator()` and then `MoveNext()`, the code in the method won't get executed.

In other words, consider this call to your "equivalent" method:

```
var ignored = OtherEnumerable.Where<string>(null, null);

```

No exception is thrown, because you're not calling `GetEnumerator()` and then `MoveNext()`. Compare that with my version where the exception is thrown *immediately* regardless of how the return value is used... because it only calls the method with the iterator block *after* validating eagerly.

Note that async/await has similar issues - if you have:

```
public async Task FooAsync(string x)
{
    if (x == null)
    {
        throw new ArgumentNullException(nameof(x));
    }
    // Do some stuff including awaiting
}

```

If you call this, you'll end up getting a faulted `Task` - rather than a `NullReferenceException` being thrown. If you await the returned `Task`, *then* the exception will be thrown, but that may not be where you called the method. That's okay in most cases, but worth knowing about.
It may depend of the scenario and your coding style. Jon Skeet is absolutely right about why they should be separated when you're using `yield` to create iterators.

BTW, I thought it could be interesting adding my two cents here: same code using *Code Contracts* (i.e. *design by contract*) behaves in a different way.

Pre-conditions aren't part of the iterator block, thus, the following code will throw a contract exception immediately if the whole pre-conditions aren't met:

```
public static class Test
{
    public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate)
    {
        Contract.Requires(source != null);
        Contract.Requires(predicate != null);

        foreach (T item in source)
        {
            if (predicate(item))
            {
                yield return item;
            }
        }
    }
}

// This throws a contract exception directly, no need of 
// enumerating the returned enumerable
Test.Where<string>(null, null);

```