Questions tagged
yield
yield is (1) a keyword that facilitates creation of generator functions, (2) a Ruby statement to transfer control from one coroutine to another, (3) a Java statement used to yield a value from a switch expression.

In python, the yield statement is only used when defining a generator function, and is only used in the body of the generator function. Using a yield statement in a function definition is sufficient to cause that definition to create a generator function instead of a normal function.

In ruby, the yield statement is in context of coroutines generally used to transfer control from one coroutine to another, for example from a method to a block passed into it as an argument.

c#’s yield return is equivalent to Python’s yield, and yield break is just return in Python. In C#, yield is used in an iterator block to provide a value to the enumerator object or to signal the end of iteration.

yield is used in ecmascript-6 and javascript-1.7 generator functions in the same way it is in Python generator functions.

In scala yield is used in for-comprehension construction. for-comprehension iterates over one or more collections and uses yield to create and return new collection.

In java, yield is a keyword used in a statement yield: <yield-target> to yield a value, which becomes the value of the enclosing switch expression.