2,127 views
State whether the following statements are True or False with reasons for your answer:

Coroutine is just another name for a subroutine.

### 1 comment

Subroutine will always starts its execution from the beginning(first line) but a co-routine will start from where it left last time.

This is why we say, co-routine has multiple entry points whereas sub-routine has only one.

Yield 'remembers' where the co-routine is so when it is called again it will continue where it left off.

For example:

  coroutine foo {
yield 1;
yield 2;
yield 3;
}
print foo();
print foo();
print foo();


Prints: 1 2 3

Note: Coroutines may use a return, and behave just like a subroutine

  coroutine foo {
return 1;
return 3;
}
print foo();
print foo();
print foo();


Prints: 1 1 1

Source - Stack Overflow

True. The subroutine is a special case of a co-routine. A co-routine is a generalized form of a subroutine which is non-preemptive multitasking.

https://en.wikipedia.org/wiki/Coroutine

by

### 1 comment

@srestha if coroutines are generalized form then can we say it is just another name of subroutine?It seems from your definition that coroutines can have multiples things and one of them is subroutine.So i think first is false

TRUE: A subroutine and a function are essentially the same thing, with one difference: A function returns some sort of value (usually via the stack or CPU register), while a subroutine does not. Whether subroutine or function, it is a block of executable code, having exactly one point of entry. A co-routine is also a block of executable code, and, just like a subroutine, it has one point of entry. However, it also has one or more points of re-entry.

1 vote
1
1,349 views