0

Can we use local variable in while loop without declared and initialized before, like for loop?

while((static int i)<5) { Some code... } Is it possible ?

6th Nov 2019, 3:20 PM
R.Basheer Mohamed
R.Basheer Mohamed - avatar
4 odpowiedzi
0
Yes you can use but what is local variable for while loop? Can you give some examples in description so we can check where you are getting issues.
6th Nov 2019, 3:49 PM
A͢J
A͢J - avatar
0
In which language? I think you are expecting this case-> In java answer is no, Because for loop has initialization section but while dont have like so if declare in while a variable, that is local to variable but initialization happend every time loop repatations, so compile error that as already defined. Ex: for(int i=0;i<5;i++){} Here i is not available outside for loop. while() { int i=0;}. /* cant do initialization here...*/ Is it what you are looking? Hoping it gives some idea for ur dougt... In c,c++ intialization needed at beginning only. so variables which are local to for loop also local to while loops..
6th Nov 2019, 4:25 PM
Jayakrishna 🇮🇳
0
Thank you so much brother.One more doubt, i know java basics.i want to become java developer, but only java was not enough to get job.so please give me some tips to become a master in java and help to get job as Java developer.
6th Nov 2019, 6:10 PM
R.Basheer Mohamed
R.Basheer Mohamed - avatar
0
You should ask this to MODs here. They can give better answer. I have no real time experiance so i cant give you best answer . . They answered this type questions already to some ones so search in q/a section. Read AMA amswers by Tashi N. In my opinion, practice more coding, try to do some projects.. Mods some others post coding challenges try to attempt them...
6th Nov 2019, 6:42 PM
Jayakrishna 🇮🇳