Home

Pre-Lab

In-Lab

Post-Lab


Logical AND

Suppose that we wish to ensure at some point in a program that two conditions are both true before we choose a certain path of execution. In this case, we can use the && [conditional AND] operator as follows:

if ( (gender == FEMALE) && (age >= 21) ) 
	females++;

The combined condition in the above if statement is true if and only if both simple conditions are true. If the combined condition is true, the if statement's body increments females by 1. If either or both of the simple conditions are false, the program skips the increment.



Megha Yanamadula | Team 1