the internal counter variable for a for loop can be updated by the code block inside the braces of the for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

the internal counter variable for a for loop can be updated by the code block inside the braces of the for loop?

For loop

12th Sep 2019, 8:20 AM
Ruggero Quaglia
Ruggero Quaglia - avatar
7 Answers
+ 1
No
12th Sep 2019, 8:57 AM
Haider Bahaa
Haider Bahaa - avatar
+ 1
Something like: int i; for(i=0; i<10; i++) { i+=3; } is possible. Of course you can use the variable i outside the for-loop only if it has been defined outside and before the loop itself.
12th Sep 2019, 11:59 AM
AndreaC
AndreaC - avatar
+ 1
Ti rispondo in italiano per far prima...in pratica hai un incremento di 3 all'interno e di 1 alla fine di ogni ciclo. Puoi visualizzare quello che succede con una printf all'interno del ciclo.
12th Sep 2019, 12:22 PM
AndreaC
AndreaC - avatar
+ 1
La variabile è la stessa, quindi hai un incremento di 3+1.
12th Sep 2019, 12:47 PM
AndreaC
AndreaC - avatar
0
Great, but inside the () i have an increment o decrement? ( maybe i+= 3 modified i=0 ??) nel senso se viene modificata anche internamente al for dopo l'istruzione i+=3
12th Sep 2019, 12:08 PM
Ruggero Quaglia
Ruggero Quaglia - avatar
0
Si ho capito che c'è un incremento di 3, ma questo incremento lo subisce anche la variabile contatore all'interno del ciclo for?
12th Sep 2019, 12:25 PM
Ruggero Quaglia
Ruggero Quaglia - avatar
0
O in incrementa soltanto di una unità come in questo ciclo for?
12th Sep 2019, 12:26 PM
Ruggero Quaglia
Ruggero Quaglia - avatar