Professional Documents
Culture Documents
BU/17C/IT/2694
The if statement is a decision-making statement in Java that allows controlling the flow of program based
on the given condition. As the condition given in the if statement is true, the program will execute the
statements inside it.
If the condition is false, the execution will move outside of the if statement or if you have used else if
and else statements, it will check the other conditions or execute the else part.
The for statement provides a compact way to iterate over a range of values. Programmers often refer to
it as the "for loop" because of the way in which it repeatedly loops until a particular condition is satisfied
3. Give the syntax for if statement, for statement, do while statement, while statement and switch
statement.
a. If statement
if (condition)
statement
Or
if (condition){
statements
b. For statement
statement sequence
}
where:
iteration expression determines change to the control variable each time a loop is repeated
c. Do while statement
do {
statement sequence
while(condition);
do...while loop
d. While statement
while(condition){
statement sequence
e. Switch statement
switch(expression) {
case constant1:
statement sequence
break;
case constant2:
statement sequence
break;
case constant3:
statement sequence
break;
A logical operator is a symbol or word used to connect two or more expressions such that the value of
the compound expression produced depends only on that of the original expressions and on the
meaning of the operator. Common logical operators include AND, OR, and NOT.