Triggering the IF statement

I have seen an example and in this part we CREATE a boolean named recvInProgressand the value is FALSE. After that we make an IF statemnet and say if recvInProgress is True and so the code runs… how?? Its false at begining. Whqt can effect that to be True… that If statement never can run… what i miss here?

void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = ‘<’;
char endMarker = ‘>’;
char rc;

// if (Serial.available() > 0) {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();

if (recvInProgress == true) {

Lower down, in a part you didn’t post, it sets it true. And because it’s static, it doesn’t revert to false when it sees the declaration at the top next time round.

Stann:
what i miss here?

Stann:
static boolean recvInProgress = false;

See Static_local_variables

What @kenwood120s said in Reply #1 is correct,

I am only posting this because the OP sent me a PM about this and I suggested he ask the question in a public Thread as I don't give private advice.

And I have a lot of sympathy with the difficulty a newcomer will have trying to figure out the implications of "static". In normal English usage the word is very similar to constant. I suspect newcomers would find it easier to understand if I had created recvInProgress as a global variable.

...R

I suspect newcomers would find it easier to understand if I had created recvInProgress as a global variable.

Perhaps you should add a couple of lines of comments to the example that explain that static makes the value in the variable persist, just like in a global variable, but, unlike a global, keeps the scope local to the function.

PaulS:
Perhaps you should add a couple of lines of comments to the example that explain that static makes the value in the variable persist, just like in a global variable, but, unlike a global, keeps the scope local to the function.

I'm not sure that I want to extend the tutorial into more general programming advice. Where would I stop?

...R

Robin2:
Where would I stop?

Perhaps you are familiar with the mythological figure Sisyphus.

You may stop when you've invented a programming language that takes as input some vague handwaving about this on this pin when that pin does that for so long and produces as output perfect C++ code that accurately predicts what the numbskull actually wanted it to do. I'm not sure what type of communication interface @PaulS's crystal ball uses, but it might be helpful to implement that as well.

I better check the downside code more deep and read some about what is static actually. Cus it seems that topic turned to be a topic to talk useless stuff on newcomers.. thats redicilous. Newcomers have more soul on learning than u dude. I have another platform to learn from more more professional people..some moderators can get me outta that frivolous forum and delete my account pls?
I dont have time for that.. end of line..

What are you going on about? What pissed you off? You got an answer and there was a little bit of back and forth about improving the lesson you had a question about. I don't see what you're upset about.

Hey Stann,..
"what i miss here?"

More than you think, closing your mind to feel hurt. Are you so loaded that you trigger? How you will deal with the compiler for long is beyond me, because that compiler is my worst coding fenemy I can tell you!

Really, dial down on the feels and you can be better at all things logic, like learning to code.
Lose all expectations, see reality without filter and you will miss less.

I was a pro for 19 years and do this as a hobby. I first learned without internet mostly on my own. I know the anciet practice of [cracking a book and reading for meaning, nearly a lost art. I learned to do that in school and unlike my stupid relatives I didn't stop looking shit up once I graduated HS. I have no degree but I wrote code for my living by learning whatever I needed to do whatever gig I had.
Do I have no soul for learning? Learning not just code but whatever business needed my custom work was my life.

I think that learning from sources I couldn't whine to helped me to not waste time and get down to the learning instead.

Just in case you missed it.....
Static variables are stored permanent on the heap same as globals. Difference is that variable names declared static in functions only compile inside of that function, but you can pass the addresses of those outside of the function since they are permanent in RAM.

If there are any unfamiliar words in that then you have words to look up just so you don't have to wait to formulate better questions if you still need better answers.

OTOH, you could throw a fit and quit if you ain't got the grit. Your ball.

Stann:
Cus it seems that topic turned to be a topic to talk useless stuff on newcomers..

This isn't stackexchange.

After reply #2, by which time your question was answered, the discussion turned to how Robin2 could improve the lesson that you queried in the first place. That's how dynamic this forum is: Robin2 (who has a number of tutorials to his credit) was actually trying to make his work better, so the next guy won't have the problem you did. Nothing wrong with that: all in the spirit of learning and what ISO and other quality folk talk of as "continual improvement": listen to your customers and make the product better.

Yeah I've noticed it gets a bit "chatty" here and sometimes I suppose a newcomer might need to sift through a few extra posts, bit when it comes down to it, your question was answered and there was no talking "useless stuff on newcomers".

Oh, and did I say this isn't stackexchange? Sure,over there, this chat's not allowed, but where's the fun in that?

edit: and don't forget, the tutorial you were working from (albeit with a part you didn't understand) exists solely because someone on THIS forum, not "another platform to learn from more more professional people", saw a need for it and took the effort to write it in the first place.