12 votes 12 votes State whether the following statements are True or False with reasons for your answer: Coroutine is just another name for a subroutine. Compiler Design gate1994 compiler-design normal assembler true-false descriptive + – Kathleen asked Oct 5, 2014 recategorized Apr 25, 2021 by Lakshman Bhaiya Kathleen 2.6k views answer comment Share Follow See 1 comment See all 1 1 comment reply vishalshrm539 commented Sep 18, 2018 reply Follow Share 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 2; //Dead code return 3; } print foo(); print foo(); print foo(); Prints: 1 1 1 Source - Stack Overflow 6 votes 6 votes Please log in or register to add a comment.
9 votes 9 votes 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 srestha answered May 12, 2016 edited Apr 23, 2021 by Lakshman Bhaiya srestha comment Share Follow See 1 comment See all 1 1 comment reply rahul sharma 5 commented Jan 22, 2018 reply Follow Share @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 1 votes 1 votes Please log in or register to add a comment.
3 votes 3 votes 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. ref: https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0ahUKEwjawbP86t3WAhWLOo8KHXxhCpsQFgg5MAM&url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F24780935%2Fdifference-between-subroutine-co-routine-function-and-thread&usg=AOvVaw3yAD5Td224hZer_CQWxfAQ rishu_darkshadow answered Oct 7, 2017 rishu_darkshadow comment Share Follow See all 0 reply Please log in or register to add a comment.