A
A
avr19722018-03-24 20:17:30
JavaScript
avr1972, 2018-03-24 20:17:30

Why is the variable i on the first iteration in the outer loop equal to 2, while in the inner it is already 3?

for (var i = 2; i <= 10; i++) {
        for (var j = 2; j < i; j++) {         
        }
    }

Can you please tell me why the variable i at the first iteration in the outer loop is equal to 2 and in the inner it is already 3?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-03-24
@avr1972

Because on the first pass of the outer loop, the inner one is not executed even once, since 2 < 2 -> false is
your cap.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question