Code:
for ( conditions ) {
expressions;
}
Code:
for ( conditions )
expressions;
|
Banned
|
|
| 16Mar2008,15:08 | #1 |
|
I am learning C by the LPE Programming in C book by Stephen Kochan. There are some confusing things in the sample programs. For instance, somewhere, with the for statement, braces have been used like this:
Code:
for ( conditions ) {
expressions;
}
Code:
for ( conditions )
expressions;
|
|
Go4Expert Founder
|
![]() |
| 16Mar2008,17:45 | #2 |
|
When you have one statement in the loops / conditional statement you do not need to use the braces
|
|
Banned
|
|
| 16Mar2008,19:17 | #3 |
|
Thanks, useful.
|
|
TechCake
|
|
| 17Mar2008,11:08 | #4 |
|
If one statement in the loops / conditional statement then it does not matter u are putiing braces or not.
But strong recommendation is that put braces like this while(conditions) { expression ; } In all excellent industries recommend this. Use of it is that No Confusion( If big and too much complex single expression) and easy to see the values by debugging) Example: while(condition) AgprsLink_mp = (AgprsMotLink *) ( InputDataSubLink) *Function(agprs_val, pVal_m, (PcmLinkDataRes_m *)( nData), (PacketFormet_m* ) (nLink) ); this is simple case, I did'nt remember, I saw manyplace too much complex sinlgle expression and it will be confusion. So better use braces for any loop with a single or more than one statements. |