diff options
Diffstat (limited to 'test/control_flow.cpp')
-rw-r--r-- | test/control_flow.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/control_flow.cpp b/test/control_flow.cpp new file mode 100644 index 000000000..9536d0504 --- /dev/null +++ b/test/control_flow.cpp @@ -0,0 +1,47 @@ +#include <cmath> +#include <algorithm> +#include <emscripten.h> + +extern "C" { + +int EMSCRIPTEN_KEEPALIVE check_if(int x) { + if (x < 10) x++; + return x; +} + +int EMSCRIPTEN_KEEPALIVE check_loop(int x) { + while (x < 100) x *= 2; + return x; +} + +int EMSCRIPTEN_KEEPALIVE check_loop_break(int x) { + while (x < 100) { + x *= 2; + if (x > 30) break; + x++; + } + return x; +} + +int EMSCRIPTEN_KEEPALIVE check_loop_continue(int x) { + while (x < 100) { + x *= 2; + if (x > 30) continue; + x++; + } + return x; +} + +int EMSCRIPTEN_KEEPALIVE check_do_loop(int x) { + do { + x *= 2; + if (x > 1000) break; + x--; + if (x > 30) continue; + x++; + } while (x < 100); + return x; +} + +} + |