is it possible to make this? if something is truth skip the next three code line

is it possible to make this?
if something is truth skip the next three code line.

thank you

You can skip any number of lines after an if, by using braces. {}
If the expression evaluates to false, the code inside the braces is not executed.

yes of course but i want the compiler still reading this code line if something is not truth

void loop() {


  buttonStateA = digitalRead (buttonPinA); 
  buttonState_B = digitalRead(buttonPinA);

  if something is truth skip the next three code line.

  buttonState_C = digitalRead (buttonPinC); 
  buttonState_D = digitalRead(buttonPinD);
  buttonState_E = digitalRead (buttonPinE);
   
  buttonState_F = digitalRead(buttonPinF);
  buttonState_G = digitalRead (buttonPinG); 
}
if (something != truth) {

  buttonState_C = digitalRead (buttonPinC);
  buttonState_D = digitalRead(buttonPinD);
  buttonState_E = digitalRead (buttonPinE);
}

jremington:

if (something != truth) {

You sly dog! You are getting worse than me. :slight_smile:

if (!something) {

or

if (something != true) {

or

if (not something) {

would be more realistic.

Where is a logical value.

By the time the if expression is evaluated, the compiler's involvement is long finished.

bool something = true;
...
.... some code which may or may not change the value of something
...

  if (! something )
 {
  // if something is true, these lines of code will not be executed.
  buttonState_C = digitalRead (buttonPinC); 
  buttonState_D = digitalRead(buttonPinD);
  buttonState_E = digitalRead (buttonPinE);
}

GrOnThOs:
yes of course but i want the compiler still reading this code line if something is not truth

As @AWOL has said the compiler is not involved in evaluating IF statements - it just turns them into machine-code that can run on an Atmega MCU. The evaluation of the IF statements only happens when the Arduino runs the program.

...R

If you really want the compiler to skip the lines ( = exclude them from your program ) then you can use the #if directive.

Robin2:
As @AWOL has said the compiler is not involved in evaluating IF statements - it just turns them into machine-code that can run on an Atmega MCU. The evaluation of the IF statements only happens when the Arduino runs the program.

...R

I know that. just it is difficult for me to express myself correctly in English

thank you all.

I've used a goto in simple code to jump over code sections instead of developing a lot of "not" code.

zoomkat:
I've used a goto in simple code to jump over code sections instead of developing a lot of "not" code.

Have you got your tinfoil hat on?

...R

Robin2:
Have you got your tinfoil hat on?

...R

No, I can use goto without a tinfoil hat. Do you have to use one?

zoomkat:
I've used a goto in simple code to jump over code sections instead of developing a lot of "not" code.

thanks this looks much more easy.

GrOnThOs:
thanks this looks much more easy.

But when it goes wrong, don't come back looking for help or sympathy :wink:

It just seems so backward and ungrateful to all those language designers who have gone to so much effort to eliminate the need for goto.

zoomkat:
I've used a goto in simple code to jump over code sections instead of developing a lot of "not" code.

This really makes me cringe.

I suppose if the code is only your own, and nobody else touches it - well, do what you want.

Honestly, though, there are only a couple of use cases for goto, and both can be resolved in other ways. The goto statement, though, can make both situations clearer, and more maintainable - but you really need to understand and know when to use it - and when not to.

...and even then, you might forgo it.

AWOL:
But when it goes wrong, don't come back looking for help or sympathy :wink:

It just seems so backward and ungrateful to all those language designers who have gone to so much effort to eliminate the need for goto.

i promise, i will use it only now, i will never touch this devil again :slight_smile:

thanks this looks much more easy.

I would very much like to see your easy version compared with the solutions presented earlier in this thread so I can see how much easier it it.

Honestly, though, there are only a couple of use cases for goto, and both can be resolved in other ways. The goto statement, though, can make both situations clearer, and more maintainable - but you really need to understand and know when to use it - and when not to.

I learn best, and maybe others too, when somebody can modify the "bad" code to be "good" code. Then I can see and maybe under how it works. If I don't understand the process to be used, then the "snippits-R-us" suggestions are kind of what dogs hear. I'm just old school where if you can provide a working solution, then "put it up". Otherwise, ... . YMMV