Can someone please simplify the following 2 lines of code.

Hi,
I came across the following 2 lines of code I extracted from the sketch on the page: Convert string to long integer on Arduino - Libraries - Arduino Forum

I don't quiet grasp them and would like to know there equivalents in normal/simple code please:

        if (inString [inCount] == EndMarker) break;    // it looks like the if condition is closed here
	{                                                                 // but then it starts with an '{' ???
                (++inCount < inLength);                      // and this looks like another condition but??
                                                                          // I know 'inCount++' but what is '++inCoiunt'??
 
                  inString[inCount] = 0;  // null terminate the string  (this one i understood :-))
        }

Q1: How come the if line is terminated with a ';' and the following line is started with a '{' ?

Q2: What is the simple equivalent of the line: '(++inCount < inLength);'

I posted the question on its relevant page but it didn't go through since it is a quiet old subject. so it thought I seek advice in a new topic, hoping someone can answer this.
Thanks.

if (inString [inCount] == EndMarker) break;    // it looks like the if condition is closed here

It makes more sense if you lay it out like this

  if (inString [inCount] == EndMarker)
  {
    break;
  }

I know 'inCount++' but what is '++inCoiunt'??

inCount++; increments the value of inCount after its value is used in the expression
++inCount; increments the value of inCount before its value is used in the expression

Thank you UKHeliBob for the reply, but still my first question: is about ending the if condition line with a ;

and starting with the {do something code} as if the if condition is still open.

And what about

(++inCount<inLength);

is it equivalent to?
if ((inCount+1)<inLength)
{
inCount=inCount+1;
}

but still my first question: is about ending the if condition line with a ;

The if condition does not end with a semicolon. It is the statement to be executed when the test returns true that ends with a semicolon.

and starting with the {do something code} as if the if condition is still open.

I believe that this is the section of code that you are looking at

     do {
        inString[inCount] = Serial.read();       // get it
        if (inString [inCount] == INTERMINATOR) break;{
          (++inCount < INLENGTH);
          inString[inCount] = 0;  // null terminate the string
        }
      }
      while (Serial.available());             // wait for input

Here it is reformatted with added comments

do
{
  inString[inCount] = Serial.read();       // get it
  if (inString [inCount] == INTERMINATOR)
  {
    break;
  }
  {   //not needed
    (++inCount < INLENGTH);  //brackets not needed
    inString[inCount] = 0;  // null terminate the string
  }   //not needed
}
while (Serial.available());             // wait for input

And what about

(++inCount<inLength);

is it equivalent to?
if (inCount<inLength) inCount++;

No it is not equivalent, but the original code does not look it works anyway. It shows all the signs of having been revised without thought, hence the extra braces and brackets

:frowning: Now I realize that I asked a silly question, when I thought I was seeking a higher level of coding

Thank you UKHeliBob for your time.

Even if it were a "higher level of coding" my advice would be to initially use coding that you understand even if you think it looks ponderous. The rule should be "get it working then improve it"

There is no such thing as a silly question. If you don't understand something then just ask, as you did.

UKHeliBob:
The rule should be "get it working then improve it"

This is a great rule that fully supports the famous SSS Strategy Rule. Always start with small thing (the basic = simple and elementary); make it work; add new thing with it; make it work and so on..

It has been highly pleasing to see the simplification of: if (inString [inCount] == EndMarker) break; into --

if (inString [inCount] == EndMarker) 
{
   break; 
}

Thanks+ @UKHeliBob!

GolamMostafa:
It has been highly pleasing to see the simplification of:

In which universe is the adding of braces a simplification?

Whandall:
In which universe is the adding of braces a simplification?

Clarification rather than simplification would be a better way to describe it.

I would use clarification if I were pedantic. :wink:

In which universe is the adding of braces a simplification?

It is in the conceptual world!

The meaning is well clarified here (to me): if (inString [inCount] == EndMarker) break;. Yet, the OP could not follow it; because, it was not simple enough for him. Reformatting helped the OP to follow the full meaning.

Sorry, no code tags or otherwise (iPad?), but this line:

(++inCount < INLENGTH); //brackets not needed

just is stupid. It increments inCount. Period. INLENGTH don't enter in to it. The expession does have a value which is discarded, computing it is pointless and one hopes optimised away:

++inCount;

a7

Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

As I said previously this portion of code looks like it has been revised and messed up in the process.

GolamMostafa:
It is in the conceptual world!

No, it's a clarification, nothing in the code is made simpler.

GolamMostafa:
The meaning is well clarified here (to me): if (inString [inCount] == EndMarker) break;.
Yet, the OP could not follow it; because, it was not simple enough for him.

No, it was too simple for him.

No, it was too simple for him.

It is your perception; the contents of my post is also a perception (to me).

Whandall:
No, it's a clarification, nothing in the code is made simpler.

No, it was too simple for him.

Simple for you maybe but complicated for the OP.

He was obviously aware of the problem caused when an if test is terminated with a semicolon. Splitting the code into several discrete lines and putting the code block in curly braces made the code simpler to understand but did not, in fact, simplify the coding

Come on guys, I am not that much of a beginner in coding, but I only thought I was discovering a new way of an 'if-else condition' syntax and maybe also a new conditional increment format that I have not seen before, but as correctly described by UKHeliBob, these were no more but some un-necessary confusing left-overs .