if then endif

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawjake

    #1

    if then endif

    I am having a dispute at work over endifs, and cannot find any treatise on
    this. So I am hoping that I can get a lot of correspondece confirming my
    belief.

    Here it is: I believe the following: (1)If a language has an "endif", then
    every "if" statement requires an endif, and (2) every "endif" goes with the
    last "if".

    For example,

    If .....
    if
    endif

    should not compile because there must be two "endif"s and the last "endif"
    goes with the last "if". The actual nested if statement is far more complex,
    and it is just being used in a presentation that is not being compiled
    (psuedo code).

    Finally, were can I find this? I don't care the language, although some
    version of Basic would be best since that is what my friend understands.

    Thanks for helping

  • zacks@construction-imaging.com

    #2
    Re: if then endif


    lawjake wrote:
    I am having a dispute at work over endifs, and cannot find any treatise on
    this. So I am hoping that I can get a lot of correspondece confirming my
    belief.
    >
    Here it is: I believe the following: (1)If a language has an "endif", then
    every "if" statement requires an endif, and (2) every "endif" goes with the
    last "if".
    >
    For example,
    >
    If .....
    if
    endif
    >
    should not compile because there must be two "endif"s and the last "endif"
    goes with the last "if". The actual nested if statement is far more complex,
    and it is just being used in a presentation that is not being compiled
    (psuedo code).
    >
    Finally, were can I find this? I don't care the language, although some
    version of Basic would be best since that is what my friend understands.
    >
    Thanks for helping
    If does not always require an End If. For example:

    If myCondition = True Then x += 1

    Comment

    • Marina Levit [MVP]

      #3
      Re: if then endif

      Well, in VB you can have:

      If someCondition Then DoSomething()

      There is no endif here. This is a perfectly valid statement

      "lawjake" <lawjake@discus sions.microsoft .comwrote in message
      news:094DB622-0639-4D46-B53C-C86571E2C93E@mi crosoft.com...
      >I am having a dispute at work over endifs, and cannot find any treatise on
      this. So I am hoping that I can get a lot of correspondece confirming my
      belief.
      >
      Here it is: I believe the following: (1)If a language has an "endif",
      then
      every "if" statement requires an endif, and (2) every "endif" goes with
      the
      last "if".
      >
      For example,
      >
      If .....
      if
      endif
      >
      should not compile because there must be two "endif"s and the last "endif"
      goes with the last "if". The actual nested if statement is far more
      complex,
      and it is just being used in a presentation that is not being compiled
      (psuedo code).
      >
      Finally, were can I find this? I don't care the language, although some
      version of Basic would be best since that is what my friend understands.
      >
      Thanks for helping
      >

      Comment

      • lawjake

        #4
        Re: if then endif

        I understand that the syntax can be "if ...then", or "if..then...els e". What
        I need the answer to is if the syntax is "if..then..else ...endif", can you
        create the code that I described above which uses and endif. Or, is there
        code that is "if...then...el se...[endif].

        Here is the exact logic that I want to know if it is correct (the
        indentations are the actual author's:

        If HoursWorked < NormalMaxHours,
        If HoursWorked 0.
        Then Display PartTimeHoursMe ssage
        End If
        Else If HoursWorked = 0,
        Then display NoHoursMessage
        Else If HoursWorked NormalMaxHours,
        Then display OvertimeMessage
        Else
        Display RegularTimeMess age
        End if


        I believe that the final endif goes with the last if?

        Thanks
        "Marina Levit [MVP]" wrote:
        Well, in VB you can have:
        >
        If someCondition Then DoSomething()
        >
        There is no endif here. This is a perfectly valid statement
        >
        "lawjake" <lawjake@discus sions.microsoft .comwrote in message
        news:094DB622-0639-4D46-B53C-C86571E2C93E@mi crosoft.com...
        I am having a dispute at work over endifs, and cannot find any treatise on
        this. So I am hoping that I can get a lot of correspondece confirming my
        belief.

        Here it is: I believe the following: (1)If a language has an "endif",
        then
        every "if" statement requires an endif, and (2) every "endif" goes with
        the
        last "if".

        For example,

        If .....
        if
        endif

        should not compile because there must be two "endif"s and the last "endif"
        goes with the last "if". The actual nested if statement is far more
        complex,
        and it is just being used in a presentation that is not being compiled
        (psuedo code).

        Finally, were can I find this? I don't care the language, although some
        version of Basic would be best since that is what my friend understands.

        Thanks for helping
        >
        >
        >

        Comment

        • tommaso.gastaldi@uniroma1.it

          #5
          Re: if then endif


          http://msdn2.microsoft.com/en-us/lib...bs(d=ide).aspx

          [i still have some doubt you are mocking us :) ]

          -t

          lawjake ha scritto:
          I understand that the syntax can be "if ...then", or "if..then...els e". What
          I need the answer to is if the syntax is "if..then..else ...endif", can you
          create the code that I described above which uses and endif. Or, is there
          code that is "if...then...el se...[endif].
          >
          Here is the exact logic that I want to know if it is correct (the
          indentations are the actual author's:
          >
          If HoursWorked < NormalMaxHours,
          If HoursWorked 0.
          Then Display PartTimeHoursMe ssage
          End If
          Else If HoursWorked = 0,
          Then display NoHoursMessage
          Else If HoursWorked NormalMaxHours,
          Then display OvertimeMessage
          Else
          Display RegularTimeMess age
          End if
          >
          >
          I believe that the final endif goes with the last if?
          >
          Thanks
          "Marina Levit [MVP]" wrote:
          >
          Well, in VB you can have:

          If someCondition Then DoSomething()

          There is no endif here. This is a perfectly valid statement

          "lawjake" <lawjake@discus sions.microsoft .comwrote in message
          news:094DB622-0639-4D46-B53C-C86571E2C93E@mi crosoft.com...
          >I am having a dispute at work over endifs, and cannot find any treatise on
          this. So I am hoping that I can get a lot of correspondece confirming my
          belief.
          >
          Here it is: I believe the following: (1)If a language has an "endif",
          then
          every "if" statement requires an endif, and (2) every "endif" goes with
          the
          last "if".
          >
          For example,
          >
          If .....
          if
          endif
          >
          should not compile because there must be two "endif"s and the last "endif"
          goes with the last "if". The actual nested if statement is far more
          complex,
          and it is just being used in a presentation that is not being compiled
          (psuedo code).
          >
          Finally, were can I find this? I don't care the language, although some
          version of Basic would be best since that is what my friend understands.
          >
          Thanks for helping
          >

          Comment

          • Marina Levit [MVP]

            #6
            Re: if then endif

            I'm not sure what language this is, but it's not VB.NET. This sort of thing
            wouldn't compile.

            Honestly, I'm not sure what you are asking. The way VB.NET syntax is
            structure, there is never really a question as to what statements are part
            of what 'if' or 'else'. Especially if you indent properly, which visual
            studio does for you.

            If you have the following example, it should be really obvious which
            statements will get executed when:

            If something Then
            If otherCondition Then
            CallMethod()
            End If
            ElseIf x Then
            DoSomething()
            ElseIf y Then
            DoSomethingElse ()
            ElseIf z Then
            DoAnotherThing( )
            End If


            "lawjake" <lawjake@discus sions.microsoft .comwrote in message
            news:0A89605A-1891-405A-9A0A-A4D37BDCCD10@mi crosoft.com...
            >I understand that the syntax can be "if ...then", or "if..then...els e".
            >What
            I need the answer to is if the syntax is "if..then..else ...endif", can you
            create the code that I described above which uses and endif. Or, is there
            code that is "if...then...el se...[endif].
            >
            Here is the exact logic that I want to know if it is correct (the
            indentations are the actual author's:
            >
            If HoursWorked < NormalMaxHours,
            If HoursWorked 0.
            Then Display PartTimeHoursMe ssage
            End If
            Else If HoursWorked = 0,
            Then display NoHoursMessage
            Else If HoursWorked NormalMaxHours,
            Then display OvertimeMessage
            Else
            Display RegularTimeMess age
            End if
            >
            >
            I believe that the final endif goes with the last if?
            >
            Thanks
            "Marina Levit [MVP]" wrote:
            >
            >Well, in VB you can have:
            >>
            >If someCondition Then DoSomething()
            >>
            >There is no endif here. This is a perfectly valid statement
            >>
            >"lawjake" <lawjake@discus sions.microsoft .comwrote in message
            >news:094DB62 2-0639-4D46-B53C-C86571E2C93E@mi crosoft.com...
            >I am having a dispute at work over endifs, and cannot find any treatise
            >on
            this. So I am hoping that I can get a lot of correspondece confirming
            my
            belief.
            >
            Here it is: I believe the following: (1)If a language has an "endif",
            then
            every "if" statement requires an endif, and (2) every "endif" goes with
            the
            last "if".
            >
            For example,
            >
            If .....
            if
            endif
            >
            should not compile because there must be two "endif"s and the last
            "endif"
            goes with the last "if". The actual nested if statement is far more
            complex,
            and it is just being used in a presentation that is not being compiled
            (psuedo code).
            >
            Finally, were can I find this? I don't care the language, although
            some
            version of Basic would be best since that is what my friend
            understands.
            >
            Thanks for helping
            >
            >>
            >>
            >>

            Comment

            • lawjake

              #7
              Re: if then endif

              I know it sounds too basic to be a question, but after programming for over
              30 years, somethings I know, but don't know where the documentation is
              anymore. I have not had to look this up in almost 30 years and did not have
              any books with the actual syntax. So I appreciate your help. Of course, I
              would have betting things to do than mock my job.

              Thanks again.

              "tommaso.gastal di@uniroma1.it" wrote:
              >
              http://msdn2.microsoft.com/en-us/lib...bs(d=ide).aspx
              >
              [i still have some doubt you are mocking us :) ]
              >
              -t
              >
              lawjake ha scritto:
              >
              I understand that the syntax can be "if ...then", or "if..then...els e". What
              I need the answer to is if the syntax is "if..then..else ...endif", can you
              create the code that I described above which uses and endif. Or, is there
              code that is "if...then...el se...[endif].

              Here is the exact logic that I want to know if it is correct (the
              indentations are the actual author's:

              If HoursWorked < NormalMaxHours,
              If HoursWorked 0.
              Then Display PartTimeHoursMe ssage
              End If
              Else If HoursWorked = 0,
              Then display NoHoursMessage
              Else If HoursWorked NormalMaxHours,
              Then display OvertimeMessage
              Else
              Display RegularTimeMess age
              End if


              I believe that the final endif goes with the last if?

              Thanks
              "Marina Levit [MVP]" wrote:
              Well, in VB you can have:
              >
              If someCondition Then DoSomething()
              >
              There is no endif here. This is a perfectly valid statement
              >
              "lawjake" <lawjake@discus sions.microsoft .comwrote in message
              news:094DB622-0639-4D46-B53C-C86571E2C93E@mi crosoft.com...
              I am having a dispute at work over endifs, and cannot find any treatise on
              this. So I am hoping that I can get a lot of correspondece confirming my
              belief.

              Here it is: I believe the following: (1)If a language has an "endif",
              then
              every "if" statement requires an endif, and (2) every "endif" goes with
              the
              last "if".

              For example,

              If .....
              if
              endif

              should not compile because there must be two "endif"s and the last "endif"
              goes with the last "if". The actual nested if statement is far more
              complex,
              and it is just being used in a presentation that is not being compiled
              (psuedo code).

              Finally, were can I find this? I don't care the language, although some
              version of Basic would be best since that is what my friend understands.

              Thanks for helping

              >
              >
              >
              >
              >

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: if then endif

                "lawjake" <lawjake@discus sions.microsoft .comschrieb:
                >I am having a dispute at work over endifs, and cannot find any treatise on
                this. So I am hoping that I can get a lot of correspondece confirming my
                belief.
                >
                Here it is: I believe the following: (1)If a language has an "endif",
                then
                every "if" statement requires an endif, and (2) every "endif" goes with
                the
                last "if".
                Not really. Every 'If...Then' block needs an 'End If', but VB also provides
                a single-line 'If...Then...' statement.

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://classicvb.org/petition/>

                Comment

                • Phill W.

                  #9
                  Re: if then endif

                  lawjake wrote:
                  Here is the exact logic that I want to know if it is correct (the
                  indentations are the actual author's:
                  >
                  If HoursWorked < NormalMaxHours,
                  If HoursWorked 0.
                  Then Display PartTimeHoursMe ssage
                  End If
                  Else If HoursWorked = 0,
                  Then display NoHoursMessage
                  Else If HoursWorked NormalMaxHours,
                  Then display OvertimeMessage
                  Else
                  Display RegularTimeMess age
                  End if
                  This code will not compile in any version of VB that I am familiar with.
                  The ','s and '.'s on the ends of lines and the total lack of 'Then's
                  render it invalid.

                  If every you're in doubt, expand every instance of If .. End If /in
                  full/ with associated indentation.

                  I /think/ this is something close to what you want:

                  If HoursWorked < NormalMaxHours Then
                  If HoursWorked 0 Then
                  Display PartTimeHoursMe ssage
                  End If

                  ElseIf HoursWorked = 0 Then
                  Display NoHoursMessage

                  ElseIf HoursWorked NormalMaxHours Then
                  Display OvertimeMessage

                  Else
                  Display RegularTimeMess age

                  End If

                  HTH,
                  Phill W.

                  Comment

                  • Branco Medeiros

                    #10
                    Re: if then endif

                    lawjake wrote:
                    <snip>
                    Here it is: I believe the following: (1)If a language
                    has an "endif", then every "if" statement requires an endif,
                    and (2) every "endif" goes with the last "if".
                    <snip>

                    And then added:
                    I understand that the syntax can be "if ...then", or "if..then...els e". What
                    I need the answer to is if the syntax is "if..then..else ...endif", can you
                    create the code that I described above which uses and endif. Or, is there
                    code that is "if...then...el se...[endif].
                    <snip>

                    If the language has an "ElseIf" construct, as most languages do, then
                    you may have several ElseIf's which are part of the original If, and
                    all will be closed by a single EndIf:

                    If Condition Then
                    Statements
                    ElseIf Condition Then
                    Statements
                    Else
                    Statements
                    End If

                    On the other side, if there's no "ElseIf" construct, or the If is
                    stated as a new statement, then yes, each if will need its own EndIf,
                    and each EndIf will close the most recent unclosed If:

                    If Condition1 Then
                    StateMent
                    Else
                    If Condition2 Then
                    Statement
                    Else
                    If Condition3 Then
                    Statement
                    End If 'Condition3
                    End If 'Condition2
                    End If 'Condition1

                    Now, notice that a language, which is the case of VB, may allow single
                    line If's, and then you may have:

                    If Condition Then
                    If Condition Then Statement
                    End If

                    where the EndIf closes the first If.

                    Regards,

                    Branco.

                    Comment

                    • zacks@construction-imaging.com

                      #11
                      Re: if then endif


                      lawjake wrote:
                      I understand that the syntax can be "if ...then", or "if..then...els e". What
                      I need the answer to is if the syntax is "if..then..else ...endif", can you
                      create the code that I described above which uses and endif. Or, is there
                      code that is "if...then...el se...[endif].
                      >
                      Here is the exact logic that I want to know if it is correct (the
                      indentations are the actual author's:
                      >
                      If HoursWorked < NormalMaxHours,
                      If HoursWorked 0.
                      Then Display PartTimeHoursMe ssage
                      End If
                      Else If HoursWorked = 0,
                      Then display NoHoursMessage
                      Else If HoursWorked NormalMaxHours,
                      Then display OvertimeMessage
                      Else
                      Display RegularTimeMess age
                      End if
                      >
                      >
                      I believe that the final endif goes with the last if?
                      I think you realize by now that there is a big difference between:

                      If ConditionA Then
                      DoSomething
                      Else
                      If ConditionB Then
                      DoSomethingElse
                      Else
                      If ConditionC Then
                      DoSomethingElse Different
                      End If
                      End If
                      End If

                      AND:

                      If ConditionA Then
                      DoSomething
                      ElseIf ConditionB Then
                      DoSomethingElse
                      ElseIf ConditionC Then
                      DoSomethingElse Different
                      End If

                      ElseIf as opposed to Else makes the structure simpler, but is more
                      restrictive on what you can do in the general Else condition path.

                      Comment

                      • lawjake

                        #12
                        thanks.

                        Thanks everyone for your help. Not only was your input very informative, but
                        incredibly quick. I now have the evidence to show my friend.

                        "Herfried K. Wagner [MVP]" wrote:
                        "lawjake" <lawjake@discus sions.microsoft .comschrieb:
                        I am having a dispute at work over endifs, and cannot find any treatise on
                        this. So I am hoping that I can get a lot of correspondece confirming my
                        belief.

                        Here it is: I believe the following: (1)If a language has an "endif",
                        then
                        every "if" statement requires an endif, and (2) every "endif" goes with
                        the
                        last "if".
                        >
                        Not really. Every 'If...Then' block needs an 'End If', but VB also provides
                        a single-line 'If...Then...' statement.
                        >
                        --
                        M S Herfried K. Wagner
                        M V P <URL:http://dotnet.mvps.org/>
                        V B <URL:http://classicvb.org/petition/>
                        >
                        >

                        Comment

                        • Michael D. Ober

                          #13
                          Re: if then endif

                          The confusion comes from C. In C, the following is perfectly valid:

                          if (condition1) {
                          block1
                          } else if (condition2) {
                          block 2
                          } else {
                          elseblock
                          }

                          Note the elseif is actually two words - else and then if. There is only a
                          single closing brace for the overall if statement. In VB this would be

                          if condition1 then
                          block1
                          elseif condition2 then
                          block2
                          else
                          elseblock
                          end if

                          In variants of Basic without elseif (VMS BASIC for example), this would be

                          if condition1 then
                          block1
                          else
                          if condition2 then
                          block2
                          else
                          elseblock
                          end if
                          end if

                          Note the two endifs at the end of the if statement.

                          Mike Ober.


                          "Branco Medeiros" <branco.medeiro s@gmail.comwrot e in message
                          news:1154013493 .366158.16820@7 5g2000cwc.googl egroups.com...
                          lawjake wrote:
                          <snip>
                          >Here it is: I believe the following: (1)If a language
                          >has an "endif", then every "if" statement requires an endif,
                          >and (2) every "endif" goes with the last "if".
                          <snip>
                          >
                          And then added:
                          >I understand that the syntax can be "if ...then", or "if..then...els e".
                          >What
                          >I need the answer to is if the syntax is "if..then..else ...endif", can
                          >you
                          >create the code that I described above which uses and endif. Or, is
                          >there
                          >code that is "if...then...el se...[endif].
                          <snip>
                          >
                          If the language has an "ElseIf" construct, as most languages do, then
                          you may have several ElseIf's which are part of the original If, and
                          all will be closed by a single EndIf:
                          >
                          If Condition Then
                          Statements
                          ElseIf Condition Then
                          Statements
                          Else
                          Statements
                          End If
                          >
                          On the other side, if there's no "ElseIf" construct, or the If is
                          stated as a new statement, then yes, each if will need its own EndIf,
                          and each EndIf will close the most recent unclosed If:
                          >
                          If Condition1 Then
                          StateMent
                          Else
                          If Condition2 Then
                          Statement
                          Else
                          If Condition3 Then
                          Statement
                          End If 'Condition3
                          End If 'Condition2
                          End If 'Condition1
                          >
                          Now, notice that a language, which is the case of VB, may allow single
                          line If's, and then you may have:
                          >
                          If Condition Then
                          If Condition Then Statement
                          End If
                          >
                          where the EndIf closes the first If.
                          >
                          Regards,
                          >
                          Branco.
                          >

                          Comment

                          • Jay B. Harlow [MVP - Outlook]

                            #14
                            Re: if then endif

                            In addition to the other comments:

                            | Here it is: I believe the following: (1)If a language has an "endif",
                            then
                            | every "if" statement requires an endif, and
                            False

                            | (2) every "endif" goes with the
                            | last "if".
                            False

                            Consider the following:

                            If x < y Then
                            If y < z Then Debug.WriteLine ("Hello World")
                            End If

                            The first If is a multi-line if, it requires an endif. The second If is a
                            single line If, no endif allowed. You can tell its a multiline If by the
                            fact there is nothing after the Then statement, likewise you can tell its a
                            single line If by the fact there *is* something after the Then statement.

                            The single line If is inside a multiline If, the End If completes the
                            multiline If, as the single line If is on (you guessed it) a single line!

                            --
                            Hope this helps
                            Jay B. Harlow [MVP - Outlook]
                            ..NET Application Architect, Enthusiast, & Evangelist
                            T.S. Bradley - http://www.tsbradley.net


                            "lawjake" <lawjake@discus sions.microsoft .comwrote in message
                            news:094DB622-0639-4D46-B53C-C86571E2C93E@mi crosoft.com...
                            |I am having a dispute at work over endifs, and cannot find any treatise on
                            | this. So I am hoping that I can get a lot of correspondece confirming my
                            | belief.
                            |
                            | Here it is: I believe the following: (1)If a language has an "endif",
                            then
                            | every "if" statement requires an endif, and (2) every "endif" goes with
                            the
                            | last "if".
                            |
                            | For example,
                            |
                            | If .....
                            | if
                            | endif
                            |
                            | should not compile because there must be two "endif"s and the last "endif"
                            | goes with the last "if". The actual nested if statement is far more
                            complex,
                            | and it is just being used in a presentation that is not being compiled
                            | (psuedo code).
                            |
                            | Finally, were can I find this? I don't care the language, although some
                            | version of Basic would be best since that is what my friend understands.
                            |
                            | Thanks for helping
                            |


                            Comment

                            • HKSHK

                              #15
                              Re: if then endif

                              Hello lawjake,
                              (1)If a language has an "endif", then every "if" statement requires an
                              endif
                              This is not the case as you can see, there is only one "End If" (in VB):

                              If a = 1 Then
                              If b = 2 Then c = 3 Else c = 4
                              End If

                              So you need only one "End If". But for readability it is usually advised
                              to use If...End If constructs, so it would then look like this:

                              If a = 1 Then
                              If b = 2 Then
                              c = 3
                              Else
                              c = 4
                              End If
                              End If

                              >(2) every "endif" goes with the last "if".
                              No, every "End If" closes the its "If" block, e.g.

                              If a = 1 Then
                              If b = 2 Then
                              If c = 3 Then
                              If d = 4 Then

                              Msgbox "Test"

                              End If ' d = 4
                              End If ' c = 3
                              End If ' b = 2
                              End If ' a = 1

                              Best Regards,

                              HKSHK

                              Comment

                              Working...