On 17/02/09 19:15, Larson, DavidX S wrote:
> Hello all,
>
> I was working on my script when I ran across this unexpected behavior with 
> the "if" statement. The doc says:
>
> :if {expr1}                     *:if* *:endif* *:en* *E171* *E579* *E580*
> :en[dif]                Execute the commands until the next matching ":else"
>                          or ":endif" if {expr1} evaluates to non-zero.
>
> I thought that meant that if {expr1} evaluated to anything other than zero 
> (such as a string) then the "if" statement passes, but it doesn't. It's 
> simple enough to reproduce:
>
>    if "atoehu"
>      echom "pass"
>    else
>      echom "fail"
>    endif
>
> Always echo's: "fail".
>
> Is the bug in the doc, vim, or in my head? I have version 7.2.106.
>
> Cheers,
> David

If {expr} is a Number, zero means "true", anything else means "false".
If {expr} is a Float, a List, a Dictionary or a Funcref, the if 
statement has a syntax error.
If {expr} is a String, it is first converted to a Number according to 
the rules explained about one page or so below ":help variables", under 
"Conversion from a String to a Number". This means that if the String 
starts with the string representation of a nonzero number it evaluates 
to TRUE, otherwise to FALSE. "atoehu" will give you "fail" but "12345" 
"0xEDCB" and "0377" will give you "pass".

Best regards,
Tony.
-- 
It is illegal to rob a bank and then shoot at the bank teller with a water
pistol.
                [real standing law in Louisana, United States of America]

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui