Nested While within an If statement

  • Hi All,

    What is the correct syntax for the following (this is my current attempt!)

    If (expr goes here)

    BEGIN

    WHILE Var1 < Var2

    BEGIN

    Do Something here

    END --While

    ELSE

    BEGIN

    WHILE Var1 < Var2

    BEGIN

    Do Something different here

    END --While

  • Every Begin needs and END

    If (expr goes here)

    BEGIN

    WHILE Var1 < Var2

    BEGIN

    Do Something here

    END --While

    END

    ELSE

    BEGIN

    WHILE Var1 < Var2

    BEGIN

    Do Something different here

    END --While

    END


  • Sorry, I missed that off when I typed the code in, I do have that extra END datement in but I am getting an error

  • I added 2 ENDs

    one right before the ELSE and one at the very end.

    I tried to space it out so it was legible but the spaces got removed from the post.


  • ahh, missed the 1st one. I'll give that a go - thanks for clarifying

  • Thanks for your help - that worked perfectly

  • Adam,

    In the future, it would help greatly if you post the error that you are getting. This was an easy one, but if you know the error, why not post it and help those who are attempting to help you? Just a thought.....

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply