kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

ctl_breakcont.c (731B)


      1 /* Nested loops exercising both `break` and `continue`. The inner loop skips
      2  * even j (continue) and breaks once it has accumulated enough; the outer loop
      3  * breaks when the running total reaches the target. volatile bounds keep every
      4  * branch real so the loop-exit / skip-edge branches round-trip. Exit code 42.
      5  */
      6 int test_main(void) {
      7   volatile int outer = 100, inner = 100;
      8   int total = 0;
      9   for (int i = 0; i < outer; i++) {
     10     for (int j = 0; j < inner; j++) {
     11       if ((j & 1) == 0) {
     12         continue; /* skip even j */
     13       }
     14       total += 1;
     15       if (total >= 42) {
     16         break; /* stop the inner loop */
     17       }
     18     }
     19     if (total >= 42) {
     20       break; /* stop the outer loop */
     21     }
     22   }
     23   return total;
     24 }