0
What is the difference between for loop in python and c++
please add the syntax of two language
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...