1 Consider the statement In some programming languages the

  1. Consider the statement:         <condition a> || <condition b> In some programming languages, the semantics of the || operator are such that if <condition a> is TRUE,  then <condition b> will not be evaluated. What is the technical term for this?  2. Based on question-1, without looking at any technical manuals or online resources,  how can you test by executing the programs to know if all the conditions are  evaluated or the conditions are partially evaluated?  Provide one to five lines of pseudocode for this testing and explain how the testing program works.  3. Based on question-1, give one real life example (including one activity,  namely <condition a>, and the other, namely <condition b>) to show that the  final judgment of its truth value is not affected by <condition b> if <condition a> is TRUE  (i.e. <condition b> does not need to be evaluated). 

Solution

1. In the statement

|| statement stands for OR condition. In this case if the 1st condition is true, even if the 2nd condition is true or false, the underlying code is execute.

Let\'s suppose <condition a>=true; and <condition b>= false;

and we have some code piece like below:

if(<condition a> || <condition b>){

// do something

}

So, in the above case, the code inside the curly braces is executed.

2. If we want that all the conditions are evaluated,we have 2 ways.

Let\'s go with <condition a>=true; and <condition b>= false;

so if we want to get both the conditions evaluated, we write:

if(<condition a> && <condition b>){

// do something

}

OR

if(<condition a> ){

// do something

}else if(<condition b>){

// do something

}

So in either of the above cases, both the conditions are evaluated.

3. Consider the following things:

int a = 10;

int b = 20;

int counter=0;

if(a<=10 || b==20){

counter++;

}

In the above code, a<=10 is true and we have OR condition, so even if the 2nd condition (b==20) is true or false is not considered and so the counter will be incremented.

 1. Consider the statement: <condition a> || <condition b> In some programming languages, the semantics of the || operator are such that if <cond

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site