You are on page 1of 3

Okegbe Akpofure Kelvin-Faith

BU/17C/IT/2694

1. What does if statement do.

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.

2. What does for statement do.

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

for(initialization; condition; iteration){

statement sequence

}
where:

initialisation sets the initial value of the loop control variable

condition is a boolean expression that continues or ends the loop

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;

default statement sequence

4. What are the logical operators.

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.

You might also like