Sunday, July 21, 2024

For Loop MCQ

 What are the three parts of the for loop in Java?

a) Initialization, condition, iteration

b) Initialization, execution, iteration

c) Execution, condition, iteration

d) Execution, iteration, termination


Which part of the for loop is optional?

a) Initialization

b) Condition

c) Iteration

d) Termination


What is the purpose of the initialization part in a for loop?

a) It defines the loop counter variable

b) It specifies the loop's condition

c) It executes before every iteration

d) It defines the loop termination condition


Which of the following statements about the for loop is true?

a) The loop body must be enclosed in curly braces {}.

b) The loop body must consist of only one statement.

c) The loop body can consist of multiple statements.

d) The loop body cannot contain any statement.


What happens if the condition in the for loop is initially false?

a) The loop body is executed at least once.

b) The loop body is skipped entirely.

c) It results in a compilation error.

d) The loop becomes an infinite loop.


How many expressions can be included in the initialization part of a for loop in Java?

a) Only one

b) Two

c) Multiple, separated by commas

d) None, it's optional


What is the role of the iteration part in a for loop?

a) It specifies the loop's condition

b) It executes before every iteration

c) It defines the loop counter variable

d) It updates the loop control variable


Which of the following is the correct syntax of a for loop in Java?

a) for (int i = 0; i < 5; i++)

b) for (i = 0; i < 5; i++)

c) for (i = 0; i < 5)

d) for (i < 5; i++)


In a for loop, what is the order of execution of the loop components?

a) Initialization, iteration, condition

b) Iteration, condition, initialization

c) Initialization, condition, iteration

d) Condition, iteration, initialization


Which part of the for loop defines when the loop should terminate?

a) Initialization

b) Condition

c) Iteration

d) Termination


Answers:


a) Initialization, condition, iteration

a) Initialization

a) It defines the loop counter variable

c) The loop body can consist of multiple statements.

b) The loop body is skipped entirely.

c) Multiple, separated by commas

d) It updates the loop control variable

a) for (int i = 0; i < 5; i++)

c) Initialization, condition, iteration

b) Condition





No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...