Interviews2 answers
Is it compulsory to initialize a variable in the first segment of the for loop or can we initialize it before the loop starts?
2 Answers
No,it is not compulsory to initialize a variable in the first segment of the for loop .You can ever initialize the variable before the loop starts .In that class ,the first segment will only have a semicolon,as shown in the following codes.
int num=0;
for (;num<=4;num=num+1)
Rahul PrajapatPosted May 27, 2015, 5:06 PM EDT
No,it is not compulsory to initialize a variable in the first segment of the for loop .You can ever initialize the variable before the loop starts .In that class ,the first segment will only have a semicolon,as shown in the following codes.
numeric num-0;
for (;num<=4;num=num+1)
Krishna Rajput SinghPosted Aug 26, 2014, 10:58 PM EDT

