Help in the code sytax

how to complete a long line code in the next line

if( val==1&&val==2&&val==3&&val==4&&val==5&&val==6&&val==7)
{ //anycode}

i want to write the condition inside the is statment or inside the code as more than line instead of one long line
another thing i wanna ask
can i do this and if not how can i do it"which is writing different operations anding them with other operations

if( (val==1&&val==2)&&(val==3&&val==4)&&(val==5&&val==6)&&val==7)
{ //anycode}
  if( (val==1&&val==2)&& 
      (val==3&&val==4)&& 
      (val==5&&val==6)&& 
      val==7
    )
  { //anycode
  }

This seems to compile just fine. Is that what you want?

And I hope the code you posted is only for demonstration purposes. It is logically impossible for val to be 1, 2, 3, 4, 5, 6, and 7 all at the same time.

First, statements like:

if (val == 1 && val == 2)

don't make sense, because val is either 1 or 2, not both. My guess is that you want to use a logical OR condition, such as:

if (val == 1 || val == 2)

Also, most compilers implement what is called "short circuiting", although I don't know if the Gnu compiler does this. My guess is that it does. Short circuiting is simply a completion of the branch on the first condition that fulfills the branch. For example,

if (val == 1 || val == 2 || num == 10 || num == 13)

With short circuiting, if val equals 1, the rest of the expression is not even evaluated and the if statement block is executed. Therefore, in complex expressions, it sometimes makes sense to put the most likely outcome first in the expression list.

Short circuiting is a required feature of C.

It is extraordinarily easy to get the logic in that sort of multiple IF statement wrong.

...R

{ //anycode}

This cannot work, because the comment prevents the closing } from being processed by the compiler.

If you really want your line of code to look like this, then use

   {  /* comment */ }

Unlike some other languages, C/C++ doesn't care where there are line breaks in your code, at all.
This would be legal:

if ( i==
1
||
j
==2 )
{  /* do something */ }

michinyon:
Unlike some other languages, C/C++ doesn't care where there are line breaks in your code, at all.
This would be legal:

if ( i==

1
||
j
==2 )
{  /* do something */ }

Not always true.
While the actual C compiler is pretty liberal, line breaks do matter particularly to the
C preprocessor.
For example.

#include "header.h"

works

#include
"header.h"

does not.

When defining complex cpp macros, line continuations are often used.
Here are few examples of function like macros that use line continuation for clarity and readability:

#define glcdio_SetRWDI(_RWstate, _DIstate)		\
do {							\
		glcdio_WritePin(glcdPinRW, _RWstate);	\
		glcdio_WritePin(glcdPinDI, _DIstate);	\
} while (0)
#define _glcdio_BLstate(pin, onlevel, offlevel, state)\
 do { state ?  glcdio_WritePin(pin, onlevel) : glcdio_WritePin(pin, offlevel) ; } while(0)

Also, line breaks matter to the compiler if inside the middle of a literal string.
Example:

char *foo = "this is a string
 that continues on another line";

does not work.
To continue a line you can use the backslash character:

char *foo = "this is a string\
 that continues on another line";

You also can't split up a comment delimeter across lines unless you use the line continuation:
example;

// this is a valid comment
/
/ this is not a valid comment
/\
/ this is a valid comment

(same is true for the /* */ comment delimiters)

--- bill

The macros and text strings require the line continuation marker ( backslash ), because in those specific contexts, the "white space" in the file ( including line breaks ), does matter.

And operators and special symbols consisting of two or more characters, such as == or // or != can't be broken apart either, right.

And the names of variables and functions and any language keywords can't be broken in the middle, either.

On the other hand, you can break strings anywhere you like

Serial.print ("The"
" quick brown"
" fox jumps over "
"the lazy"
" dog");

Jiggy-Ninja:

  if( (val==1&&val==2)&& 

(val==3&&val==4)&&
     (val==5&&val==6)&&
     val==7
   )
 { //anycode
 }



This seems to compile just fine. Is that what you want?

And I hope the code you posted is only for demonstration purposes. It is logically impossible for val to be 1, 2, 3, 4, 5, 6, and 7 all at the same time.

thx man thats what i meant and of course the code I posted is only for demonstration purposes.