Loading ...
Sorry, an error occurred while loading the content.

400Re: [ruby-india] Syntax error : Breaking an if statement across lines

Expand Messages
  • Kiran Kumar
    Feb 19, 2007
    • 0 Attachment
      a = 15;

      if (a > 10 \
      and \
      a < 20)

      print "A is #{a}"
      end

      You can use a \ to break across the lines

      from the ruby manual

      "Ruby programs are sequence of expressions.
      Each expression are delimited by semicolons(;) or newlines.
      Backslashes at the end of line does not terminate expression"


      On 2/18/07, gishu pillai <gishu_pillai@...> wrote:
      >
      >
      > Hi,
      > As part of my long delayed ruby learning attempt, I
      > just wrote up a piece on test driving a small program
      > at
      >
      > http://madcoderspeak.blogspot.com/2007/02/test-driving-conways-game-of-life-in.html
      >
      > While doing this, I hit a couple of hiccups one of
      > which is...
      >
      > if I break this line into multiple lines for
      > readability..
      >
      > if ( (obColony.getLiveNeighboursCount(iRow,iCol) < 2)
      > or
      > (obColony.getLiveNeighboursCount(iRow,iCol) > 3) )
      > then
      > obNewColony.markCell( iRow, iCol, false )
      > end
      >
      > I get...
      >
      > GameOfLife.rb:10: syntax error
      > or
      > (obColony.getLiveNeighboursCount(iRow,iCol) > 3) )
      > then
      >
      > if I have both the ORed clauses on the same line,
      > everything works fine.
      >
      > Why is this ?
      >
      > Thanks,
      > Gishu
      >
      >
      >
      >
      > ____________________________________________________________________________________
      > Do you Yahoo!?
      > Everyone is raving about the all-new Yahoo! Mail beta.
      > http://new.mail.yahoo.com
      >
      >
      >
      > Yahoo! Groups Links
      >
      >
      >
      >


      [Non-text portions of this message have been removed]
    • Show all 3 messages in this topic