2
Reply

Is it compulsory to initialize a variable in the first segment of the for loop or can we initialize it before the loop starts?

Krishna Rajput Singh

Krishna Rajput Singh

Aug 27, 2014
3k
0

    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 Singh
    August 27, 2014
    2

    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 Prajapat
    May 27, 2015
    1