End of If (Leftwheelrotations Rightwheelrotations)
This document provides some basic rules for indenting C programs: 1) Use meaningful variable names instead of single letters. 2) Name functions to be readable, like describing the action. 3) Align opening and closing braces and add end comments. 4) Use spaces instead of tabs to nest statements and improve readability.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
37 views1 page
End of If (Leftwheelrotations Rightwheelrotations)
This document provides some basic rules for indenting C programs: 1) Use meaningful variable names instead of single letters. 2) Name functions to be readable, like describing the action. 3) Align opening and closing braces and add end comments. 4) Use spaces instead of tabs to nest statements and improve readability.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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) }