90.5k views
2 votes
State the syntax of for-loop

answer correctly asap

User Himal
by
5.5k points

1 Answer

2 votes

Answer:

The answer to this question is given below in the explanation section

Step-by-step explanation:

The for-loop is used in all programming languages to iterate a number of statement to a specific number or to a specific condition.

The syntax of for-loop is given below:

for (initialization; condition; update) {

// body of-loop

}

Initialization initializes variables and executed only once. This shows that from where the for-loop will begin.

Condition parts represent the loop-condition, if true the body of for-loop gets executed.

Update-updates the value of initialized variables and again checks the condition. It will increment/decrement the intialized variable.

For example: the for-loop that count total achieved numbers of 5 subjects of a student

for (int subject =1, subject>=5, subject++)

{

//count number of each subject

// count total.

}

User Evfwcqcg
by
5.8k points