When does shortcircuit evaluation affect expressions or Wh

When does \"short-circuit evaluation\" affect expressions && or ||? What type of expression can be used as the *condition* of an \"if\"? A \"switch\"? Practice tracing code that uses multiple alternates (if-else-if). I.e., determine which \"if\" or \"else\" part will be executed. Under what circumstances must you use braces {} to form a \"block\" (compound statement)? Write a loop to count up to 10. Then, down from 10. Then by 2\'s.

Solution

2)

Short circuit evaluation expressions

Lets consider a condition

false && ____

Here in this condition if the left hand side is false then it won’t check whether the right hand side true or false .As the final result is false.

When coming to the ||

True || _____

Here it is not necessary to check the right hand side if the left hand side is already true.As the final result is true.

_________________________

3)

If we want to check whether the number is in the range of values then we have to use this condition as an expression in case of if-else ladder

We can’t write this type of expression in case of switch statement.

In case of switch statement ,we can use only single expression for multiple choices.

____________________________

4)

In case of if-else –if statements.The control starts checking the conditions.If the condition of the first statement is executed and if the condition is true then the remaining condition statements will not get executed.The control will check the next condition in the if – else ladder only if the previous condition is false.Like this each and every condition it will check in that ladder until the condition is true

__________________________

5)

If we want to execute a particular task.If the task involves multiple statements then we have to use.Then we have to place all those multiple statements in a single block of code by placing it in curly braces {}.

_________________________

6)

//count from 1 to 10

For(int i=1;i<=10;i++)

{

}

//count from 10 to 1

For(int i=10;i>0;i--)

{

}

//counting from zero to 10 by 2’s

For(int i=0;i<=10;i+=2)

{

}

//counting from 10 to zero by 2’s

For(int i=10;i>=0;i-=2)

{

}

___________________________

 When does \
 When does \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site