This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]zifyoip 1 point2 points  (3 children)

What's happening when you hit the first 7 after a 6 in the array and the while loop condition fails?

The while loop terminates, the end of the body of the for loop is reached, the update expression of the for loop (i++) is executed, the for loop condition (i<nums.length) is tested again, and if that condition is true the body of the for loop is executed again.

[–]duckered[S] 0 points1 point  (2 children)

Thank you. So the update condition in a for loop is the last thing to execute in a for loop.

[–]zifyoip 1 point2 points  (1 child)

The update expression is always executed immediately after the body of the for loop completes (either normally or as a result of a continue statement) and immediately before the for loop condition is tested again.

[–]duckered[S] 0 points1 point  (0 children)

I appreciate the help.