2 commands in one line

techElder

Well-known member
The ":" separates commands on one line.

DO : LOOP

FOR i = 1 TO 10 : NEXT i

It is more difficult to troubleshoot a program sometimes with more than one command structure on a single line, and there isn't any real advantage to writing code that way.

Instead of putting another command on the line, add a comment to describe what the line does or what the section of code does. You will be much happier to see the comments later. :)
 

westaust55

Moderator
The new line symbol ( : ) is discussed near the bottom of page 6 in PICAXE manual 2.
http://www.picaxe.com/docs/picaxe_manual2.pdf

A space character is also recognized by the programming editor (for historical reasons) however I strongly recommend NOT using the space alone as it can even confuse the PE and makes reading the code to help with question harder.
Even with the use of the colon ( : ) as a new line separator/character I also recommend a space each side for readability.
Compressing the program source code does not save space in the downloaded program file.
See also Whitespace on the same page in the manual.
 

ARTAUD

New Member
Thanks for your answers.

My pupils use s2p scratch. But I don't have all commands in this software.
I can use basic block an write the commands that I want.
But I can write only one line and make comments in order to explain.

It's more easy.
 

inglewoodpete

Senior Member
I occasionally put two commands on one line but it's not very often.

As Tex mentions, it can be harder to read or debug the code.

Ease of debugging code is a big one. I find it best to have any routine (Eg Subroutine) fit onto a single screen (or window in the editor), making it easier to trace the ins and outs of the routine. On occasion, I have merged commands into one line to reduce the number of lines, helping to fit a large routine onto the screen.

Code segment types that lend themselves to simple, single line merges are:
Code:
[color=Black]bTVRespPtr1 [/color][color=DarkCyan]= [/color][color=Navy]0[/color][color=Black]: bTVRespPtr2 [/color][color=DarkCyan]= [/color][color=Navy]0      [/color][color=Green]'Initialising pointers[/color]

[color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Black]bValue: [/color][color=Blue]SerTxd([/color][color=Red]" After: "[/color][color=Black], #[/color][color=Purple]bit7[/color][color=Black], #[/color][color=Purple]bit6[/color][color=Black], #[/color][color=Purple]bit5[/color][color=Black], #[/color][color=Purple]bit4[/color][color=Black], [/color][color=Red]"."[/color][color=Black], #[/color][color=Purple]bit3[/color][color=Black], #[/color][color=Purple]bit2[/color][color=Black], #[/color][color=Purple]bit1[/color][color=Black], #[/color][color=Purple]bit0[/color][color=Black], [/color][color=Blue]CR[/color][color=Black], [/color][color=Blue]LF) [/color][color=Green]'Log byte var as bits[/color]

[color=Blue]Do[/color][color=Black]: [/color][color=Blue]Loop Until [/color][color=Black]iHandshake [/color][color=DarkCyan]= [/color][color=Black]True      [/color][color=Green]'Only exit when a condition is met[/color]

[color=Purple]ptr [/color][color=DarkCyan]= [/color][color=Navy]72[/color][color=Black]: [/color][color=Blue]Do Until [/color][color=Purple]ptr [/color][color=DarkCyan]= [/color][color=Navy]80[/color][color=Black]: wVar [/color][color=DarkCyan]= [/color][color=Black]wVar [/color][color=DarkCyan]+ [/color][color=Purple]@ptrinc[/color][color=Black]: [/color][color=Blue]Loop [/color][color=Green]'Sum some contiguous bytes from RAM[/color]
 
Top