Quick actions

cmd+k|ctrl+k

Navigation

Languages

Coroutine

Snippet info

Language

C

Visibility

public

Author

evine

Created

2016-02-07T19:53:25Z

Updated

2016-02-07T20:11:25Z

#include <stdio.h>

// Does not handle multi yields.
void coroutine_(int i)
{
    int loopLength = 8; // for loop, while loop would not need this and next line.
    if(i < loopLength)
    {
        //First Pass
        if(i == 0)
        {
            printf("Start\n");
        }
        //Body
        printf("%i\n",i);
        //Last pass
        if(i == loopLength-1)
        {
            printf("End\n");
        }
    }
}

void coroutine()
{
    static int i = 0;
    coroutine_(i++);
}

int main() {
    for(int a = 0; a < 20; a++)
    {
        coroutine();
    }
    return 0;
}
INFO