+ 3

What if for-loop?

22nd Dec 2016, 7:11 AM
Shruti S
Shruti S - avatar
7 Answers
+ 24
 It allows code to be executed repeatedly.  For instance, if you want sum of integers from 1 to 10 you can write int sum=0; for(int i=0;i<=10;i++) { sum+=i; }
22nd Dec 2016, 8:01 AM
Remmae
Remmae - avatar
+ 3
you mean to say like "for loop" inside "if loop" then yes this is possible like this int x=10; if (x>5) { for (int i=0;i<5;i++) cout<<i<<endl; }
22nd Dec 2016, 10:32 AM
Sumit Lokhande
Sumit Lokhande - avatar
+ 2
Sumit, I think in thus case you don't need the if loop because the for loop do the job....right?
27th Dec 2016, 10:24 PM
Shirit Dori
Shirit Dori - avatar
+ 2
@shirit if loop can help to provide double condition check. otherwise yes only for loop will be ok
29th Dec 2016, 1:18 AM
Sumit Lokhande
Sumit Lokhande - avatar
0
Yes Sumit, we called nested loop.
21st Jan 2017, 4:49 PM
Amit pandey
Amit pandey - avatar
0
yes if doesn't need
12th Mar 2017, 3:27 AM
Naveen Reddy Maredi
Naveen Reddy Maredi - avatar
0
plz suggest best resource for data structures and sortings
12th Mar 2017, 3:28 AM
Naveen Reddy Maredi
Naveen Reddy Maredi - avatar