0

Is there a syntax to include multiple initialization or final expression on a for loop in javascript?

For instance initialize two variables, or increment two variables.

I don't see anything about it on the MDN documentation.

2

1 Answer 1

2

I think this is what you're asking for....

for (var i = 0, a = 1; i < 10; i++, a += 2) {
    console.log(i, a);
}

output:

0 1
1 3
2 5
3 7
4 9
5 11
6 13
7 15
8 17
9 19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.