Which of the following is the correct syntax of FOR?

  1. for ( increment; initialize; test)

  2. for ( initialize; test), increment

  3. for ( initialize; test; increment)

  4. for ( test; initalize; increment)


Correct Option: C
Explanation:

To solve this question, the user needs to know the correct syntax of the FOR loop used in programming. The FOR loop is used for executing a block of code repeatedly for a fixed number of times, and it has three parts: initialization, test, and increment.

Now, let's discuss each option and explain why it is right or wrong:

A. for ( increment; initialize; test): This option is incorrect because the syntax of FOR loop starts with the initialization, followed by the test, and then the increment. In this option, the increment is mentioned first, which is not the correct order.

B. for ( initialize; test), increment: This option is incorrect because the correct syntax of the FOR loop requires three statements separated by semicolons. This option has only two statements with a comma in between, which is not the correct syntax.

C. for ( initialize; test; increment): This option is correct. The correct syntax for the FOR loop is to start with the initialization statement, followed by the test statement, and then the increment statement, all separated by semicolons. This option has all three statements in the correct order.

D. for ( test; initalize; increment): This option is incorrect because the correct syntax of the FOR loop requires the initialization statement to be mentioned before the test statement. In this option, the test statement is mentioned first, which is not the correct order.

Therefore, the answer is: C. for ( initialize; test; increment).

Find more quizzes: