0

What is the difference between for loop in python and c++

please add the syntax of two language

29th Sep 2017, 8:31 AM
Stefin Shaji
Stefin Shaji - avatar
1 Answer
+ 4
The original C-for loop inherited by C++ is simply used in the following way : for ( initial variable(s); test expression(s); update expression(s) ) {} Eg - for(int i=0;i<5;i++) cout<<i+1; //Prints 12345 In C++, a test case can be be an equality comparision as well, just anything. The python for loop is more range based and isof following form : for var in range(): #code to be executed Unlike C's for loop, it has a smaller and cleaner syntax, but cannot work with complex conditions that easily. You need if else and break for those...
29th Sep 2017, 2:09 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar