Code Readability
is this code read able or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int j = 0;
for(int i=0;i<10;i++)
{
j = i+1;
while( j != 0)
{
cout<<" hello ";
j--;
}
cout<<endl;
}
_getch();
}
|
Please, compare with this form:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int j = 0;
for(int i = 0; i < 10; i++)
{
j = i+1;
while( j != 0)
{
cout<<" hello ";
j--;
}
cout<<endl;
}
_getch();
}
|
Not readable at all without indentation. Like what condor did.
You need indentation to help indicate scope and loop blocks.
Also, the trend is to stop writing "using namespace std;"
1 2 3
|
using namespace std; // bad
::std::cout << "hello"; // good
|
Last edited on
@Sarmadas
If OK please mark this thread as Solved.
Topic archived. No new replies allowed.