+ 3

What is the result of a after this for loop run" for( int a=1;a<6;++a){} because first this for loop which type format see

that is 1st see int a or a<6 or ++a

12th Feb 2018, 1:57 PM
Vibeeshanan Vibee
Vibeeshanan Vibee - avatar
5 odpowiedzi
+ 16
int a; for (a=1; a<6;++a); //or int a; for (a=1; a<6;++a){} /*final value of a will be 6 , bcz after a=6 ... condition'll become false& so loop stops*/
12th Feb 2018, 5:01 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
a doesn't exist as it's scope is limited to the loop.
12th Feb 2018, 2:02 PM
John Wells
John Wells - avatar
+ 2
As John said, it a doesn't exist in the outside scope. However, you can do something like this: int a; for (a=1; a<6;++a) ; a will be 6 after the loop.
12th Feb 2018, 2:40 PM
Vlad Serbu
Vlad Serbu - avatar
+ 1
john wells told correct but i don't ask that matter . i asked the for loop first think it what a<6 or ++a first what do it this for loop
13th Feb 2018, 6:13 AM
Vibeeshanan Vibee
Vibeeshanan Vibee - avatar
0
for loop will first check the condition i.e., a<6 and after that it will increment the value of a
19th Feb 2018, 6:19 PM
Vrutika Gaikwad