Shop OBEX P1 Docs P2 Docs Learn Events
Real fast - simpl syntax — Parallax Forums

Real fast - simpl syntax

PhilldapillPhilldapill Posts: 1,283
edited 2008-01-05 03:22 in Propeller 1
I have a loop that keeps repeating...

· repeat
··· if condition is satisfied
····· break out of loop and continue
· continuing code...

How do I break out of the loop? In C, it would just be "break" or "return" in the case of returning from the function, but in this case I just want to continue.

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-05 00:45
    The command you are looking for is QUIT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BTXBTX Posts: 674
    edited 2008-01-05 00:49
    Or.
    Repeat until "condition is satisfied"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-05 00:49
    THANK YOU! Now, another thing... I THINK I've stored a string of characters in a byte array... "KeyName[noparse][[/noparse]16]" being the name with a max length of 16 characters. How do I convert it to a string that I can put on the TV?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-05 00:54
    Most of the routines that handle strings assume a C-type string using a zero byte at the end. Most of the display drivers (and serial I/O driver) have a subroutine called "str" which is passed the address of a C-type string and displays it on the display. You would call "display.str(@KeyName)" where "display" is the name of the object used as a display driver. Have a look at the source code for "tv_text.spin" (included with the Propeller Tool) for example and you'll see that routine and several others that convert numbers to decimal / hexadecimal / binary form for display.

    You could also do
    repeat i from 0 to 15
    ·· display.out(KeyName[noparse][[/noparse] i ])


    Post Edited (Mike Green) : 1/5/2008 12:59:08 AM GMT
  • BTXBTX Posts: 674
    edited 2008-01-05 00:55
    Correct me please, if I'm wrong:

    Repeat i from 0 to 16
    tv.str(string(KeyName))

    Seems to not appear the KeyName[noparse][[/noparse]/code]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-05 00:56
    The easiest method is to place a 0 value immediately following the array (or if the field is < 16 characters making sure the strlen+1 contains a 0), then use the str method of your TV text driver.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BTXBTX Posts: 674
    edited 2008-01-05 00:58
    Sorry something is wrong with my explorer...can't show brackets for the array

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-05 01:07
    You have to place spaces before and after the brackets, [noparse][[/noparse] i ] when written without spaces is interpreted by the forums as italic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-05 01:10
    Thanks guys... New problem(well, sorta). What I'm ultimately doing, is reading the command from a tv remote, and displaying the corresponding key name(like "mute" or "Left Arrow") on the TV screen. I have a lookup table that is MaxKeys in length(KeyID[noparse]/noparse]MaxKeys] as a variable). Each KeyID stores a particular code, such as 00002B14, in it. Then, I WANT to have a second lookup table named "KeyName[noparse][[/noparse" which would store strings. If this is anything like C, I would have to have MaxKeys number of "KeyName" variables, with each KeyName storing a string of 16 characters max. Now, HOW do I do that with spin syntax?
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-05 01:15
    Grrrr, one more thing. In the "case", if you have many different cases, but want a default case, how do you implement it? Again, in C, it would just be Default:
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-05 01:20
    VAR
       long KeyName[noparse][[/noparse]MaxKeys * 17]
    

    17 so that you have space for the 0 termination, the 3rd letter of the 2nd field would be KeyName[noparse][[/noparse]1*17 + 2] (arrays start with 0 index, so each component of the index (record # and offset)·are subtracted by 1)

    other: is the default case (this information is in the manual)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-05 01:24
    Thanks Paul, but I prefer to let other people do the dirty work for me which let's me ride on other's shoulders, thereby making me look good!(kidding of course) I need to break out the manual I guess and relearn it. Thanks again guys!
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-05 02:19
    Philldapill said...
    ... thereby making me look good!
    You need not fear for that smile.gif
    said...
    I need to break out the manual I guess and relearn it.
    There is a much underrated thing in the HELP menu: "Quick Reference". This is "SPIN on a Page"! Browsing through it from time to time will soon expand your knowlege of SPIN!

    Post Edited (deSilva) : 1/5/2008 2:29:22 AM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-05 02:19
    There's a command which you may find helpful in your app, lookdownz provides a faster method to do content searching (give a value get an index back), used in conjunction with your array you can do·an arbitrary index array (and array whose indices are any vaue). So lets say your remote has 3 buttons (POWER, PLAY and STOP), and thier codes are 4B, 7C and 7F, you can display the string with this line of code:

    ·tvtext.str(KeyName[noparse][[/noparse]17 * lookdownz(code : $4B, $7C, $7F)])

    code is the code value that you are displaying the name for, KeyName contains the string POWER starting at index 0, PLAY starting at index 17 and STOP at index 34, all other values in KeyName are 0. The effect of this code is to make an array whose indicies are $4B, $7C and $7F

    If you want to get even "spiffier" you can use variable length strings using a combo lookup and lookdown:

    OBJ
      tvtxt : "TV_Text"
     
    PUB Main | code
      ...
      code := ...
      ...
      tvtxt.str(lookup(lookdown(code : $4B, $7C, $7F) : @pwrstr, @playstr, @stopstr))
     
     
    DAT
    pwrstr BYTE "POWER", 0
    playstr BYTE "PLAY", 0
    stopstr BYTE "STOP", 0
     
    

    Pretty cool huh?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 1/5/2008 2:29:27 AM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-05 02:24
    BTX said...
    Correct me please, if I'm wrong:
    Repeat i from 0 to 16
    tv.str(string(KeyName[noparse][[/noparse] i ])

    Have you tried it? Of course not smile.gif
    "string" is no command but a "directive"; it instructs the compiler to allocate some space preset by CONSTANTs only.

    The classical program to output a string is
    PRI outputstring(theStringAddress)|c
     REPEAT WHILE (c := BYTE[noparse][[/noparse]theStringAddress++])
           out(c)
    
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-05 02:28
    Thank you desilva. I understand why the string must be "zero terminated"... so that C results in being false, stopping the while loop. I love this chip!(Just thought I'd get that out in the open and profess it)
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-05 02:35
    Oh, Paul, this is totally off topic, but any idea what kind of price range a Prop II protoboard would run? I can't wait.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-05 02:39
    no I don't

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-05 02:41
    Last time he said: "...considerably more" lol.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-01-05 02:44
    Thats a bit of a misquote, that was describing the difference in price for a propstick like format vs protoboard.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-05 02:52
    I couldn't resist...
    Negroponte says the OLPC notebook will be $80 end of this year
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-05 02:58
    Sorry, what's the OLPC notebook you speak of desilva?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-05 03:10
    Long thread, short postings.
    What is the topic again?
    Winter wind rambles.

    My haiku for the day. smile.gif

    -Phil
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-05 03:22
    5-7-5
    Well done, Phil!

    ... and you even did't forget the reference to nature and season smile.gif

    Post Edited (deSilva) : 1/5/2008 6:19:29 PM GMT
Sign In or Register to comment.