/**
 *  Coroutines in C implementation
 *  Copyright (C) 2010 Matous Jan Fialka, <http://mjf.cz/>
 *  Released under the terms of The MIT License
 */

#include <stdio.h>

int
test(void)
{
	static int i, state = 0;
	switch (state) {
	case 0:
		goto L0;
	case 1:
		goto L1;
	}
L0:
	printf("start\n");
	for (i = 0; i <= 10; i++) {
		printf("test: %d\n", i);
		state = 1;
		return i;
L1:		;
		printf("resume: %d\n", i);
	}
	return -1;
}

int
main(void)
{
	int i;

	while ((i = test()) != -1)
		printf("result: %d\n", i);
	return 0;
}
