Can we initialise a variable inside the body of the while loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we initialise a variable inside the body of the while loop?

If yes, can it be used after the loop is completed?

30th Jul 2016, 6:18 AM
Rachit Singhvi
Rachit Singhvi - avatar
2 Answers
0
if condition does not use the variable it is fine else there will be a dump..
1st Aug 2016, 1:59 PM
RB Vijey Shankar
RB Vijey Shankar - avatar
0
you need to declare the data type of the variable before the loop. then inside the loop, you can initialize it. yes it can be used after the loop is completed.
3rd Aug 2016, 10:58 AM
Arundhati
Arundhati - avatar