Page 1 of 1

Can't end IF statements

Posted: Thu Feb 20, 2014 2:11 pm
by monkey
Hi all,

Can somebody please tell me what I'm doing wrong here?

I've typed the following code:
repeat with x = 1 to number of characters in currentWord
if wordArray[x] is " "
then put "/" after field "legend"
else put "*" after field "legend"
end if
end repeat
On application, I receive the following error:
card "game": compilation error at line 49 (repeat: missing 'end repeat'), char 4
It seems that LiveCode wants me to end repeat before ending IF, which makes no sense to me. If I do it that way, I'm then told that IF is not a valid handler.

I've looked online at examples of other IF statements and can't see anything wrong with what I've done.

So it must, therefore, be something bleeding obvious.

Any and all help appreciated!

Thanks again

Re: Can't end IF statements

Posted: Thu Feb 20, 2014 2:20 pm
by Klaus
Hi Monkey,

this should do:

Code: Select all

...
 repeat with x = 1 to number of characters in currentWord
    if wordArray[x] is " " then
      put "/" after field "legend"
    else
      put "*" after field "legend"
    end if
  end repeat
...
Note he "position" of THEN and ELSE!


Best

Klaus

Re: Can't end IF statements

Posted: Thu Feb 20, 2014 2:59 pm
by monkey
D'oh!

Thanks again! :)

Re: Can't end IF statements

Posted: Thu Feb 20, 2014 3:02 pm
by Klaus
Yo :D

There are several ways to use IF THEN ELSE with or without END IF,
but I never "got" them, so I always the most verbose but also most
readable version like in my example. 8)