Structured Control Flow (Brain Dump)

2021-02-02

Note: This is a “brain dump” article, and subject to be cleaned up.

Categories of Structured Control Flow

Pseudo/Partial Categories

Examples of Extensions

Examples in Odin

foo :: proc(x: int) -> (val: int, err: Error) {
	defer if err != nil {
		// handle clean up
	}

	if x > 0 {
		err = .Bad_Error;
	} else {
		val = -x*2 + 1;
	}

	// returns all the named return values without having the manual specify them
	return;
}
the_cases: switch x {
case 1:
	loop: for y > 0 {
		do_thing(&y);
		if y == 3 {
			break the_cases;
		} else if y == 2 {
			continue loop;
		}
		do_other_thing(&y);
	}
case 2, 3:
	do_thing(&y);
	fallthrough;
case 4:
	do_other_thing(&y);
}

Categories of Unstructured Control Flow