No Syntax error?

PADJ

Member
This piece of code is generated by the Datalogger Wizard. Why does the highlited line not cause an error?
Code:
if address > 4095 then memory_full
	i2cslave %10100000, i2cslow, i2cword
	writei2c address,(data0)
	pause 10
	readi2c address,(temp_byte)
	if temp_byte <> data0 then ee_error

	[B]temp_word = address + 12288  	writei2c temp_word,(data7) [/B]   
	pause 10
	readi2c temp_word,(temp_byte)
	if temp_byte <> data7 then ee_error
Even this is ok
Code:
[B]temp_word = address + 12288writei2c temp_word,(data7)[/B]
 

nick12ab

Senior Member
Excellent discovery - that has eliminated the need for using the colon to use multiple commands on one line - it works for other commands too!
Code:
if b0 = 1 then serout 0,N2400,(b0) end if

high 0 low 0 high 0 low 0 toggle 0

b0 = 0 + 1 b0 = 4

serout 0,N2400,(b0)serout 0,N2400,(b0)let b0 = b0 + 4
do loop
In PICAXE Manual 1, it says this:
Commands are normally placed on separate lines. However if desired the colon
:)) character can be use to separate multiple commands on a single line e.g.
if pin1 = 1 then : high 1 : else : low 1 : endif
It's possible that this is meant to say that the colon is optional (because it uses the word can not must) so that would explain why it works.
 

PADJ

Member
Excellent discovery - that has eliminated the need for using the colon to use multiple commands on one line
You can get rid of some of the spaces too!

Code:
high 0low 0high 0low 0toggle 0
if b0=1then serout 0,N2400,(b0)endif
Can you write a 1 line program? Yes
Code:
L:toggle 0pause 1000goto L
 
Last edited:

Technical

Technical Support
Staff member
The compiler will always do its best to work out what you mean.
Howeveritisareallyawfulhabittogetinto - don't do it! One line per command is far better.
 

westaust55

Moderator
Omission of the colon as a new line separator is well known and seems more prevalent amongst some new comers when they first start posting code.
While the Programming editor accepts the practice, I have several times in the past recommended against leaving out the colon ( : ).
Doing so makes it more difficult to read through code and know for sure exactly what was intended.

It does not save any program space when you download a program to a PicAxe chip.

As Technical has stated: "DON'T DO IT"

EDIT:
By way of past example, see post 8 (by nick12ab) and 9 (by myself) here: http://www.picaxeforum.co.uk/showthread.php?19252-28x2-PWM-Output
where lack of both colons and spaces ( lines such as:if w8>490 then let w7=1endif) was covered.

And another example (see post 5):
http://www.picaxeforum.co.uk/showthread.php?14968-20x2-Retic-5station-led-display
 
Last edited:

John West

Senior Member
I like to put as much code on each line as I possibly can, so I don't have to bother scrolling when I'm working on debugging my code, which I have to do a lot. ;)
 

Buzby

Senior Member
I like to put as much code on each line as I possibly can, so I don't have to bother scrolling when I'm working on debugging my code, which I have to do a lot. ;)
I do just the opposite !.

With one command per line it's easy to 'rem out' a command, or add a debug line between commands.

Multi-command lines have their place, but I don't use them unless it makes reading the code easier.
 

JimPerry

Senior Member
Lines may affect speed - many years ago, when I was editing TRS80 books, I wrote a BASIC program ine one line (255 characters).

It ran like a snail - taking 3 minutes to process one page of input.
The same program seperated into 30 lines ran in 10 seconds with the same input.

This was interpreted not compiled - but may still apply. :confused:
 

PADJ

Member
Omission of the colon as a new line separator is well known and seems more prevalent amongst some new comers when they first start posting code.
While the Programming editor accepts the practice, I have several times in the past recommended against leaving out the colon :)).
Doing so makes it more difficult to read through code and know for sure exactly what was intended.
I was not advocating leaving out colons or spaces. The code was generated by the Datalogger wizard in PE, and as a new comer I found that line confusing. It should be fixed. Of course if 'search' worked us newcomers would be able to find this 'well known' stuff.
 

hippy

Ex-Staff (retired)
The code was generated by the Datalogger wizard in PE, and as a new comer I found that line confusing. It should be fixed.
Apologies for that and it should not have happened. There is obviously something in the wizard that does not generate a new line as intended and we will investigate that.
 
Top