• lukstru@piefed.social
    link
    fedilink
    English
    arrow-up
    2
    ·
    20 hours ago

    You need another goto end right before the end_false_if:, otherwise the false code will always run

    • I tested it, it works as it is.

      #include <stdio.h>
      #include <stdbool.h>
      
      void main(){
              bool true_or_false = true;
              if(true_or_false){
                      goto if_true;
              }
              printf("This code runs only if false.\n");
              goto end_false_if;
      if_true:
              printf("This code runs only if true.\n");
      end_false_if:
              printf("This code always runs.\n");
      }
      

      If true, it jumps to if_true, then runs other code. If false, the if gets skipped, if false code gets run, then it skips over if true code.