0

Loops

Can anyone say what's counter and max_index?

24th Mar 2020, 10:14 PM
Prajwal RIOR
Prajwal RIOR - avatar
1 Respuesta
0
First, counter is the loop variable that usually starts at index 0 (That's how it starts), through each loop iteration, "counter" gets updated once.. So from 0 to 1. Each time the expression is true, the loop executes whatever statement(s) it has, and then updates the counter by one. By doing so, it checks the expression again, comparing counter to whatever you're comparing to and repeats. Second, "max_index" (assuming that's how many times we iterate total) tells the loop how many times we want to execute the body statement(s) inside the loop. Because we start at 0, we must end at max_indec - 1. 0 is inclusive and max_index is not. So you can look at it like: [(counter, max_index))
25th Mar 2020, 1:06 AM
Gabe
Gabe - avatar