On 2/17/09, 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:
It does - but a string, evaluated in a numeric context, evaluates to zero, unless the string can be interpretted as a number. :echo "abcd" / 1 0 :echo "256" / 1 256 :echo "0x10" / 1 16 :echo "010" / 1 8 :echo "atoehu" / 1 0 > if "atoehu" > echom "pass" > else > echom "fail" > endif > > Always echo's: "fail". Right. Because "atoehu", as a Number, is 0. > Is the bug in the doc, vim, or in my head? I have version 7.2.106. ~Matt --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---