Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What type of if function code should I use?

There are two types of if function codes:

if (condition1) {
  function1
}
if (condition2) {
  function2
}
function3

if (condition2) {
  function1
} else {
  if (condition3) {
    function2
  } else {
    function3
  }
}

I don’t know what is the correct way to use the if function code, I hope everyone can tell me.

Feel free to leave a comment if you need more information.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What type of if function code should I use? I would appreciate any help. Thank you in advance!

>Solution :

else only runs when the if is not true. What you need to use depends on what you want it to do.

In your first example, if both condition1 and condition2 are true then both function1 and function2 will run. function3 will run regardless of the conditions.

In your second example when condition2 and condition3 are true, only function1 will run because it will never go in the else block. So function3 will only run when both condition2 and condition3 are false, and function2 will only run when condition2 is false and condition3 is true.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading