+ 2

What is the work of i in this For Loop?

Ok so this program was given in my book as an example of valid expression in the for loop and as per the format of for loop there is initialization, test loop counter and increment or decrement operator. But in test there is no condition for the counter i instead only the name of the variable is mentioned. So can anyone please tell me how is the test counter working... https://code.sololearn.com/cBPOq6VD1O8B/?ref=app

18th Nov 2019, 3:00 PM
Tanmay Bora
4 Respostas
+ 3
Tanmay Bora this is amazing meathod to terminate the loop As you must be knowing that loop always decreases the value of "i" after implementing loop. But when "i" becomes 0 then its Boolean value (that is false) is considered instead of its numerical value and as soon as a false is evaluated by loop, it breaks it
18th Nov 2019, 3:23 PM
Arsenic
Arsenic - avatar
+ 1
Ohk thanks Arsenic for helping out so quick...
18th Nov 2019, 3:25 PM
Tanmay Bora
+ 1
The loop proceeds until the expression in the middle (i) is false. As long as i holds a nonzero value, its boolean state is true. If i equals zero, its boolean state is false and the loop is exited.
18th Nov 2019, 3:25 PM
Michael
Michael - avatar
+ 1
Thank You Miachel tooo...
18th Nov 2019, 3:27 PM
Tanmay Bora