Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Some basic rules for indenting c programs

1) Name of variable: Use variable names which are meaningful like


LeftWheelRotations and RightWheelRotations. Don't use variable names such as x,i
etc.
2) Name of subfunctions: Use function names which are readable and
understandable. Like using void moveForward (int numOfRotations)
instead of void fwd(int x).
3) Align of { } : Align the opening { and closing } of each if else, switch, loop. Also write
a comment at each closing brace of each statement.
if (LeftWheelRotations < RightWheelRotations){
rotationcount++;
}// end of if(LeftWheelRotations < RightWheelRotations)
else if(LeftWheelRotations > RightWheelRotations){
rotationcount--;
}//end of else if(LeftWheelRotations > RightWheelRotations)
4)Use of spaces : Use space in nested statements to make program more readable.
Don't use tabs.
void main()
{
int count, sensorvalue=0;

for (count=1; count<=10; count++){


sensorvalue=Read_sensor();
if (sensorvalue < 100){
moveforward();
}// end of if (sensorvalue<100)
else if (sensorvalue >700){
moveleft();
} // end of if (sensorvalue>700)
}

You might also like