How to write an if statement with multiple || and && in C? [closed]












-2















What is a concise way to write an if statement with more than many || and && in C?



I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?



eg. can I write something like:



if ((a = 1||2||4||6) && b == 8 && c == 10)

//do something


This doesn't seem to work...










share|improve this question















closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.























    -2















    What is a concise way to write an if statement with more than many || and && in C?



    I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?



    eg. can I write something like:



    if ((a = 1||2||4||6) && b == 8 && c == 10)

    //do something


    This doesn't seem to work...










    share|improve this question















    closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49


    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





















      -2












      -2








      -2


      1






      What is a concise way to write an if statement with more than many || and && in C?



      I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?



      eg. can I write something like:



      if ((a = 1||2||4||6) && b == 8 && c == 10)

      //do something


      This doesn't seem to work...










      share|improve this question
















      What is a concise way to write an if statement with more than many || and && in C?



      I want to only execute a printf statement if a either 1,2,4 or 6 AND b = 8 and c = 10, can I put all these conditions into the same if statement?



      eg. can I write something like:



      if ((a = 1||2||4||6) && b == 8 && c == 10)

      //do something


      This doesn't seem to work...







      c if-statement multiple-conditions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 2 '18 at 9:00









      M.S Chaudhari

      20.9k669137




      20.9k669137










      asked May 18 '14 at 8:17









      user3649227user3649227

      13112




      13112




      closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









      closed as too broad by devnull, dandan78, JJJ, A5C1D2H2I1M1N2O1R2T1, Blackhole May 18 '14 at 23:49


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


























          2 Answers
          2






          active

          oldest

          votes


















          6














          if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)





          share|improve this answer































            2














            It might be better to write this with a switch statement inside of an if instead.



            if(b == 8 && c == 10) {
            switch(a) {
            case 1:
            case 2:
            case 4:
            case 6:
            printf("value worksn");
            }
            }





            share|improve this answer






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              6














              if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)





              share|improve this answer




























                6














                if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)





                share|improve this answer


























                  6












                  6








                  6







                  if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)





                  share|improve this answer













                  if ((a == 1 || a == 2 || a == 4 || a == 6) && b == 8 && c == 10)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 18 '14 at 8:20









                  Edward ClementsEdward Clements

                  4,54821524




                  4,54821524

























                      2














                      It might be better to write this with a switch statement inside of an if instead.



                      if(b == 8 && c == 10) {
                      switch(a) {
                      case 1:
                      case 2:
                      case 4:
                      case 6:
                      printf("value worksn");
                      }
                      }





                      share|improve this answer




























                        2














                        It might be better to write this with a switch statement inside of an if instead.



                        if(b == 8 && c == 10) {
                        switch(a) {
                        case 1:
                        case 2:
                        case 4:
                        case 6:
                        printf("value worksn");
                        }
                        }





                        share|improve this answer


























                          2












                          2








                          2







                          It might be better to write this with a switch statement inside of an if instead.



                          if(b == 8 && c == 10) {
                          switch(a) {
                          case 1:
                          case 2:
                          case 4:
                          case 6:
                          printf("value worksn");
                          }
                          }





                          share|improve this answer













                          It might be better to write this with a switch statement inside of an if instead.



                          if(b == 8 && c == 10) {
                          switch(a) {
                          case 1:
                          case 2:
                          case 4:
                          case 6:
                          printf("value worksn");
                          }
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 18 '14 at 8:20









                          MakotoMakoto

                          81.5k17127176




                          81.5k17127176















                              這個網誌中的熱門文章

                              Xamarin.form Move up view when keyboard appear

                              Post-Redirect-Get with Spring WebFlux and Thymeleaf

                              Anylogic : not able to use stopDelay()