# Does yield return false; have special meaning in Unity3d C# scripts?

In Unity, we have some special things for coroutines that are additional to normal C#.

for example, we can use

yield return WaitForSeconds(5.f);

to have a coroutine wait 5 seconds before continuing.

What do yield return false; and yield return true; do?

• hm I'm not sure if yield return true does something special. But yield return null simply pauses for a frame, so I suspect that yield return false has the exact same effect (also yield return 0 since 0 false null are all the same under the hood) – jhocking Aug 5 '14 at 15:47
• @jhocking “since 0 false null are all the same under the hood” Why does that matter? C# is very much a strongly-typed language, so most of the time, how something looks “under the hood” doesn't matter. For example, you can't just do if (0) or if (null), unlike in C and C++. – svick Aug 5 '14 at 18:32
• shrug then it doesn't matter. all I know is that yield return 0 works; apparently because of the reason MLM explained – jhocking Aug 5 '14 at 20:23
• This is not additional to normal C#. The yield keyword has been around since at least C# 2.0. All Unity does is call it coroutine and handles the generated iterator and the values returned from it in a way that you can cause non-blocking delays in the execution of your code. – O. R. Mapper Aug 6 '14 at 6:20
• @Almo: That is simply because WaitForSeconds is not declared. As soon as you declare a method called WaitForSeconds that takes a float argument and that returns the element type of the enumeration you are implementing, it would compile again. Hence, yield is not special to Unity. If anything, the WaitForSeconds method is special to Unity, but even then, it does not extend the language C#, but is simply an extra method that was written using standard C#. – O. R. Mapper Aug 12 '14 at 13:39

The only possible yield values the scheduler understands are:

• Classes derived from YieldInstruction (WaitForSeconds, WaitForEndOfFrame, WaitForFixedUpdate, AssetBundleCreateRequest, AssetBundleRequest and Coroutine
• a WWW object
• "any other value" which isn't one of the above.

If "any other value" is yielded (which includes "null" a string value any other basic type such as int, bool, ... or a reference to an arbitrary object which isn't one of the above mentioned) the scheduler will "schedule" the coroutine for the next frame.

The WaitForEndOfFrame and others of the like, are just blank functions that tag the YieldInstruction in order to decide what to do in the engine.
The default case seems to be WaitForEndOfFrame. So if you yield return something that doesn't have a special meaning, such as a bool, it is the same as WaitForEndOfFrame.
rutter commented about another special case: yield return null
All of the Unity Coroutines including yield return null, run before the frame renders except for WaitForEndOfFrame. You can find rutter's awesome answer over at Unity Answers explaining this further (nice diagrams included).