Main loop suitable for use in an embedded system