Home > DeveloperSection > Forums > what is short circuit operator in java
jayprakash sharma
jayprakash sharma

Total Post:117

Posted on    October-01-2014 6:56 AM

 Java Java  OOPS 

 1 Reply(s)
 1153  View(s)
Rate this:
example of short circuit operator

Kamlakar Singh
Kamlakar Singh

Total Post:194

Posted on    October-03-2014 11:47 PM

The OR operator results in true when one operand is true, no matter what the second operand is.
The AND operator results in false when one operand is false, no matter what the second operand is.
If you use the || and &&, Java will not evaluate the right-hand operand when the outcome can be determined by the left operand alone.
The following code shows how you can use short-circuit logical operator to ensure that a division operation will be valid before evaluating it:

class Program


    static void Main(string[] args)


            int x = 0;

            int y = 0;

            for(int i=0;i<10;i++)


                if (x++ < 7 || y++ < 5) ;






Modified On Oct-03-2014 11:49:23 PM

Don't want to miss updates? Please click the below button!

Follow MindStick