How to do this part of programming ... ?

Hello …

Inside the main loop of sketch I had If-else condition , if the condition is true , the compiler should executes what is in the if-body . but I need to add some thing else which is : if for any loop the condition was true and the compiler executed what is in the if-body , I want the compiler to execute what is in the if-body for next loop even when the condition is false . I wish the question is clear .

I wish the question is clear .

Me too.

I had If-else loop

There is no such thing.
There is a "while" loop, a "do..while" loop and a "for" loop (which is just a "while" loop in a fancy frock), and the "goto", which we keep chained-up in the cellar.

I wish the question is clear .

No. What you want to do requires compound if statements. if(someCondition || thatConditionWasTrueLastTime)

Why do you want to do whatever it is you want to do if the condition is false?

Where IS your code?

AWOL:

I wish the question is clear .

Me too.

I had If-else loop

There is no such thing.
There is a "while" loop, a "do..while" loop and a "for" loop (which is just a "while" loop in a fancy frock), and the "goto", which we keep chained-up in the cellar.

sorry I meant If-else condition .

but how to do that ?

Well, first you post your code.

PaulS:

but how to do that ?

Well, first you post your code.

I had no code yet , I just want to understand the idea in my mind to start programming .

bool wasTrue=false;

void loop()
{

if (condition || wasTrue)
  {dostuff();
   wasTrue=true;
  }

KenF:

bool wasTrue=false;

void loop()
{

if (condition || wasTrue)
  {dostuff();
   wasTrue=true;
  }

thanks a lot

But in the code above it will do that just for the first time that condition is true . I need it for any time the condition became true it should enter condition in next loop even when the condition is false .

I need it for any time the condition became true it should enter condition in next loop even when the condition is false .

Can you please give an example of what you want to do as what you have written does not make sense to me.

But in the code above it will do that just for the first time that condition is true

Look carefully I've used the OR function. The first time the condition becomes true wasTrue gets set. From then on EVERY time through the loop it will keep doing it, until you do something to reset wasTrue back to false.

RoboTemad:
I had no code yet , I just want to understand the idea in my mind to start programming .

If you haven't got as far as writing code then just write all the steps that you want to happen as a series of short sentences - one on each line

The Thread Planning and Implementing a Program may help point you in the right direction

To avoid future confusion the compiler is a program on your PC that converts the text of your code into machine code that the Arduino can understand. The compiler doesn't play any role when the code is actually running and making decisions based on your IF statements. So it is technically incorrect to say "the compiler should executes what is in the if-body" A more correct sentence would be "the Arduino should execute what is in the if-body"

...R

  boolean  a = true;
 
void loop() { 
  
  if( a )
  {
   a = !a; // complement 
   //Serial.print( " True ");
   Serial.println (a);     // process 
  }
  else
  {
    //Serial.print( " False ");
    Serial.println (a);   // process 
  }
  delay(2000);
  
}

Moderator edit: code tags added. Vaclav, for future reference, it's the control marked with a # on the post editor's toolbar, or you can add them manually like this put your code here

I just wrote a simple example show what I need to do

void setup() {

int X=0
}

void loop() {
 
  
  if (ConditionIsTrue)
  {
    X=X+1;
    Serial.println("X");
  }
  
  
}

Loop 1 : ConditionIsTrue is true (for example if it is true )
X=1;
Loop 2 : ConditionIsTrue if true or false it should exexute X=X+1 and Serial.println("X");
X=2;
Loop 3 : ConditionIsTrue is False
X=2;
Loop 4 : ConditionIsTrue is False
X=2;
Loop 5 : ConditionIsTrue is False
X=2;
Loop 6 : ConditionIsTrue is true
X=3;
Loop 7 : ConditionIsTrue if true or false it should exexute X=X+1 and Serial.println("X");
X=4;
Loop 8 : ConditionIsTrue is false
X=4;
Loop 9 : ConditionIsTrue is false
X=4;
.
.
.
.
.
.

I just wrote a simple example show what I need to do

That is not an explanation of WHY you want to do that. A concrete, real-life story is needed. What you are doing is bizarre. The WHY behind it is essential.

PaulS:

I just wrote a simple example show what I need to do

That is not an explanation of WHY you want to do that. A concrete, real-life story is needed. What you are doing is bizarre. The WHY behind it is essential.

thanks

It is a very big code with many classes and libraries I couldn't post it , in the code I have a function that dependent on sensor reading , if the sensor senses any thing , the function should call , after that I want to call the function in next time (next loop) even when sensor didn't sense , shortly, Each call to the function after verification condition , it should follow with another call .

My method works!

It is a very big code with many classes and libraries

And yet you don't know how to do compound if statements. Well, good luck.

KenF:
My method works!

thanks KenF

But in the code you post, it will do that just for the first time that condition is true and if I reset wasTrue to false it will cancel the true that set inside if-body .

for example :

bool wasTrue=false;
int X=0;
void loop()
{

if (condition || wasTrue)
  {
X=X=+1;
   wasTrue=true;
  }

wasTrue=false;

Loop 1 : if condition is true
X=1;
wasTrue=true;
Loop 2 :
wasTrue=false
.
.
.
.

Watch carefully

bool wasTrue= false

loop executes once

Condition is true SO
suff happens
wasTrue is set to TRUE

loop executes again

was true is STILL true , it has not been reset to false

condition isn't true BUT wasTrue IS
SO stuff happens again

The only way you are going to stop it happening again is execute the command
wasTrue=false
somewhere WITHIN your loop or the stuff that you are doing.

The only way you are going to stop it happening again is execute the command
wasTrue=false
somewhere WITHIN your loop or the stuff that you are doing.

If I reset wasTrue to false in the loop , it will cancel the true that set inside if-body .