If then else endif nested

Status
Not open for further replies.

camerart

Well-Known Member
Hi,

Can someone clarify these please:

IF a=b THEN
IF c=d THEN
Do something
ELSE
Do somethng different
ENDIF
ENDIF

1st/ if a =b and c=d
2nd if a=b and c does not = d
3rd if a does not = b and c=d

What does THEN mean?

I use these all the time, but have to play around till they do what I want. It woul;d be easier if I had a crib sheet.
Thanks, Camerart.
 
Normally the statements run like this..

if a=b then do this!! The else isn't required!!
if a didn't equal b if would dismiss and carry on!!

You can also have two if criteria..
Code:
if a=b and c=d then
   do this
else
  do that
endif
 
Hi Ian,

Thanks, I think the other two examples I posted are what's called nesting, but so far I haven't found a clear explanation.

C.
 
1st/ if a =b and c=d > Do something
2nd if a=b and c does not = d > Do somethng different
3rd if a does not = b and c=d > do nothing

This is one if nested in another if. If the first if is true it evaluate the second (nested) one
IF a=b THEN

IF c=d THEN
Do something
ELSE
Do somethng different
ENDIF

ENDIF

THEN is only part of the structural of IF statement, the compiler needs it to know that it's the end of the conditions.
 
Hi

Nesting means you are placing an If-Then statement inside another If-Then statement:

# if Y=1 then evaluate the nested if-then-else code block
If (Y=1)

# begin nested if-the-else code block
If (X=1) Then
# do this
Else
#do this instead
EndIf
# end of nested if-the-else code block

EndIf
 
No!!
IF( statement is true ) THEN do the true thing
ELSE do the untrue thing
ENDIF
 
I have looked at it several times.. The Logic is right but it looks misplaced.... The branch after the "then" isn't entirely correct.

I have just done this..

 
I have looked at it several times.. The Logic is right but it looks misplaced.... The branch after the "then" isn't entirely correct.
To me it looks like camerart answered 3 separate questions and the A in question 1 is not the A in question 2 or 3.
I can't see the differences between your answer and his answer to question 3 .
 
Last edited:
Hi,

There are three different examples.

Ian, can you open my image with 'say' PAINT (start > all programs> accessories> PAINT) and point to the offending 'THEN' please.

I hope your correct Zahwi, it's not as easy as it looks.

C.
 
Ian, can you open my image with 'say' PAINT (start > all programs> accessories> PAINT) and point to the offending 'THEN' please.
Its not offensive, Its just you mentioned that it was the THEN of the loop that confused you...

As I said your logic is spot on.... Realistically there should be a branch off of the true...

My take:----
 
Hi Ian,
I see! It's the way we see things. As long as I've got the logic correct, that's the main thing. I suppose that after each NOT TRUE the branch should go to it's ENDIF for accuracy.

When I read THEN IF, it doesn't ring true to me, but that's ok.

Thanks for all inputs, it's clearer now.

EDIT: With ENDIFs connected. Is the logic still correct? Are all the ENDIF connections correct?

C.
 

Attachments

  • IF THEN ELSE ENDIF NESTED.gif
    8.5 KB · Views: 318
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…