Loop a special word?

fisherman

New Member
In an effort to learn about using the ds18b20 in a program I downloaded programs, see how they are used etc.
One program for the 08m uses the readtemp command from pin 1, and displays the output on pin 2.
The word (loop is used like main with a colon. When I try the simulator the error says that the loop needs a do.
I take this to mean an action is required.
When I replace the word (loop) with (top) all runs fine.

Don,t recall reading anything about loop, do and can't find an answer. What am I missing?
 

westaust55

Moderator
Yes. As in:

Do
:
:
LOOP (until / while / etc)

See manual 2 (V6.9) page 47, LOOP is a keyword in BASIC.

Where did you download the program from.
There were some examples previously in the PICAXE manuals using loop: as a label but those have been corrected.
 
Last edited:

fisherman

New Member
:confused: Ok I will chase that info down, but why would someone post a program using the word if it had a special function?
 

westaust55

Moderator
Loop is a programming key word

:confused: Ok I will chase that info down, but why would someone post a program using the word if it had a special function?
As mentioned, in my previous post, some of the PICAXE manuals previously had examples that wrongly used loop: as a label.
From manual 3 V4.2:

Maybe the DO...LOOP construct did not exist in an earlier version of PICAXE BASIC.
 

Attachments

Last edited:

fisherman

New Member
do,,,loop

:confused:
Not sure what site the program came from on the net but see that I will have to broaden my search skills as I missed the
do,,,,loop
tx
 

Dippy

Moderator
"...why would someone post a program using the word if it had a special function? "
-Stuff on the Internet may have been sitting there for years and languages develop over the intervening years.
It could be some schoolboy project from 5 years ago.



New commands = New Reserved Words = Variables/Labels not usable by us.


In addition to all the words/constants used in commands have a look at "Additional Reserved Words" in the BASIC Manual (Manual 2).

Have a read through all that and, in conjunction with the PE error messages, you should be able to sort out the problem.

Armed with the 'knowledge' it doesn't take much effort to change "loop:" to "MyLoop:" or whatever you prefer.

AND, of course, with the changes in the language you can probably improve the code you have just cut'n'paste :)
 

SD2100

New Member
The DO LOOP commands were added to the programming editor in version 5.0.5, before then the DO's and LOOP's could be used for labels and variables etc but not any more. Lots of other commands were added in that version as well.... :D

5.0.5
Enhanced BASIC compiler supports these new commands:
- if...then gosub
- if...elseif...else...endif
- select...case...else..endselect
- do...loop (until / while)
- on...goto
- on...gosub
- readoutputs
- exit / if...then exit
- inc / dec
- high / low / toggle / input / output / reverse now support multiple outputs
- read / write / peek / poke now support multiple and word variables
 

westaust55

Moderator
BASIC keywords

Thanks for that confirmation/update Phil.

PE V5.0.5 precedes my time using PICAXE chips.

The Rev Ed manuals took a while longer to catch up and as others have already noted, there is a lot of old code out there in the big wide world based on old software, including some posted that likely never worked at any time.
 

SD2100

New Member
While on the commands topic:

The SENSOR command still keeps appearing in the commands.rw file even though it was removed from the compiler in V4.1.0, is this reserved for future use or can it be deleted from the commands file and be used for a variable/label etc.... :confused:
 

hippy

Ex-Staff (retired)
Re : SENSOR

I've made a note of that, and if it is no longer required it probably could be removed.

It seems possible to use it anyway though the colour highlighting isn't correct ...

#Picaxe 20X2
symbol sensor = b1
b0 = sensor

#Picaxe 20X2
sensor:
Goto sensor

You can manually delete "sensor" from the commands.rw file to correct colour highlighting. Take a backup first in case anything goes wrong !
 

benryves

Senior Member
The PICAXE manual 2 included with the Programming Editor 5.2.7 and available here both contain an invalid program in the readtemp command:
Code:
main:
    readtemp 1,b1 ' read value into b1
    if b1 > 127 then neg ' test for negative
    serout 7,N2400,(#b1) ' transmit value to serial LCD
    goto loop
neg:
    let b1 = b1 - 128 ' adjust neg value
    serout 7,N2400,("-") ' transmit negative symbol
    serout 7,N2400,(#b1) ' transmit value to serial LCD
    goto main
It looks like an attempt was made to fix it but the job was not quite finished (still one reference to "loop" and a dodgy "if" statement). :)
Code:
do
    readtemp 1,b1 ' read value into b1
    if b1 > 127 then ' test for negative
        let b1 = b1 - 128 ' adjust neg value
        serout 7,N2400,("-") ' transmit negative symbol
    end if
    serout 7,N2400,(#b1) ' transmit value to serial LCD
loop
 
Last edited:

westaust55

Moderator
For Rev Ed/technical,

that is on page 155 in V6.9 of manual 2

goto loop


The IF statement construct is okay however. It is what is referred to as "single line structure"
If you are only branching to another location (label)
with no other commands or maths then the ENDIF is not required as in IF . . (test here). . THEN . . (do things here) . . ENDIF
 
Last edited:

benryves

Senior Member
The IF statement construct is okay however. It is what is referred to as "single line structure"
If you are only branching to another location (label)
with no other commands or maths then the ENDIF is not required as in IF . . (test here). . THEN . . (do things here) . . ENDIF
You're quite right! The editor reported a problem with the IF statement so I assumed it wasn't happy with the single line IF statement syntax and converted it to a block, which "fixed" it. However, the problem is really in the label name - another reserved word, "neg". Changing it to something else also fixes the code. Sorry!
 
Top