Best convention for coding IF THEN in SX/B?
RobotWorkshop
Posts: 2,307
From source examples and the SX/B help file I can see several different ways of structuring IF THEN statements. Is there a preferred method for readability of SX/B code? I can write it several different ways and if there is best practice and established convention i'd rather follow that to start with. In particular the example below:
Wait_Ack:
IF ACK = 0 THEN
GOTO Wait_Ack:
ENDIF
or
Wait_Ack:
IF ACK = 0 THEN Wait_Ack
or
Wait_Ack:
IF ACK = 0 GOTO Wait_Ack
I've got my programs working as expected and just want to make sure they are going to be easy to follow for someone else.
Best Regards,
Robert
Wait_Ack:
IF ACK = 0 THEN
GOTO Wait_Ack:
ENDIF
or
Wait_Ack:
IF ACK = 0 THEN Wait_Ack
or
Wait_Ack:
IF ACK = 0 GOTO Wait_Ack
I've got my programs working as expected and just want to make sure they are going to be easy to follow for someone else.
Best Regards,
Robert
Comments
Personally I would use the 2nd version. It leaves out the extraneous and redundant GOTO, and it is very compact without sacrificing readability. If you had more going on in the loop other than the check on ACK, then the first version makes sense since it has an ENDIF to contain anything that needs to be grouped within the loop.
Others may feel differently.
Thanks,
PeterM
Post Edited (JonnyMac) : 1/26/2007 11:04:49 PM GMT
Robert