If then and loops

2,849 views
Skip to first unread message

Nick G

unread,
Oct 20, 2011, 1:05:31 AM10/20/11
to E-Prime
I'm having trouble with the below code. E-Prime seems to want a
'then' statement immediately following the 'if' statement:

if present.RESP = "z" and strHit2 = "aHi" or strHit2 = "aLo" strHit2 =
"aMed" then
Confidence.RESP = strHit2

If one response on the present slide is selected, I just want E-Prime
to allow one of the three responses in the string hits. How should
this code look?

Peter Quain

unread,
Oct 20, 2011, 1:15:33 AM10/20/11
to e-p...@googlegroups.com

try searching e-basic help for "If...Then...Else (statement)". Note
the conditions under which you need to close the conditional with "End If"

>--
>You received this message because you are subscribed to the Google
>Groups "E-Prime" group.
>To post to this group, send email to e-p...@googlegroups.com.
>To unsubscribe from this group, send email to
>e-prime+u...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/e-prime?hl=en.

Nick G

unread,
Oct 20, 2011, 1:47:20 AM10/20/11
to E-Prime
The E-basic help doesn't say whether an if-then statement can have
multiple conditions. Seems limiting to not have that sort of
functionality.

-Nick

Nick G

unread,
Oct 20, 2011, 1:52:40 AM10/20/11
to E-Prime
You know in C you can just
if (condition1 && condition2)

Peter Quain

unread,
Oct 20, 2011, 2:01:59 AM10/20/11
to e-p...@googlegroups.com

Note in description: "statement or group of statements."

-----------------------
Syntax 1

If condition Then statements [Else else_statements]

Syntax 2

If condition Then
[statements]
[ElseIf else_condition Then
[elseif_statements]]
[Else
[else_statements]]
End If
-------------------------
Description

Conditionally executes a statement or group of statements.

Comments

The single-line conditional statement (syntax 1) has the following parameters:

Parameter Description

condition Any expression evaluating to a Boolean value.
statements One or more statements separated with colons. This
group of statements is executed when condition is True.
else_statements One or more statements separated with colons. This
group of statements is executed when condition is False.


The multiline conditional statement (syntax 2) has the following parameters:

Parameter Description

condition Any expression evaluating to a Boolean value.
statements One or more statements to be executed when condition is True.
else_condition Any expression evaluating to a Boolean value. The
else_condition is evaluated if condition is False.
elseif_statements One or more statements to be executed when
condition is False and else_condition is True.
else_statments One or more statements to be executed when both
condition and else_condition are False.

-------------------------------

Peter Quain

unread,
Oct 20, 2011, 2:33:27 AM10/20/11
to e-p...@googlegroups.com

Google can be your friend:

Using If...Then...Else Statement

      ' Dimension the variable.
      Dim x As Integer
      ' Place a value in x.
      x = Int(Rnd * 100)
      ' Display the value of x.
      MsgBox "The value of x is "
& x & "."
      ' Test to see if x less than or equal to
10.
      If x <= 10 Then
         ' Display a message
box.
         MsgBox "X is
<=10"
      ' Test to see if x less than or equal to
40 and greater than 10.
      ElseIf x <= 40 And x > 10 Then
         MsgBox "X is
<=40 and > 10"
      ' Test to see if x less than or equal to
70 and greater than 40.
      ElseIf x <= 70 And x > 40 Then
         MsgBox "X is
<=70 and > 40"
      ' Test to see if x less than or equal to
100 and greater than 70.
      ElseIf x <= 100 And x > 70 Then
         MsgBox "X is <=
100 and > 70"
      ' If none of the above tests returned
true.
      Else
         MsgBox "X does not
fall within the range"
      End If
 

        
        
        
        



At 04:47 PM 20/10/2011, you wrote:

Peter Quain

unread,
Oct 20, 2011, 2:33:54 AM10/20/11
to e-p...@googlegroups.com

In E-basic help look for "And (operator)" ... links to other
operators at bottom of the page.

Michiel Spape

unread,
Oct 20, 2011, 3:26:40 AM10/20/11
to e-p...@googlegroups.com
Avoiding pedantry:
In basic you can just
if (condition1 and condition2) then ... which works almost exactly the same as the & in C (but not &&, which would be if (condition1) {if (condition2) {...}}.

Anyway, the answer is much shorter:
IF (present.RESP = "z" and strHit2 = "aHi") or (strHit2 = "aLo" and strHit2 = "aMed") THEN

Confidence.RESP = strHit2

END IF

Note the end if. All on one line is also possible, but note it freaks out if you then use end if. THIS is what is exasperating - if not necessarily limitating - about ebasic.
More likely, your code makes no sense in some other degree, though. Notice me putting in the brackets - they are useless - and comes before or anyway - but i think where you got stuck was in the length of the IF statement. I mean, strHit2 is never both aLo and aMed, right? In your original code it did not have an operator (or strHit2 = "aLo" strHit2 = ?), so, given a wild guess, you actually want something like this:
IF present.RESP = "z" and (strHit2 = "this" or strHit2 = "that" or strHit2 = "nothisactually") THEN
Confidence.RESP = strHit2
END IF

Notice that due to the precedence of and over or - both in C and basic - this is possible, but your previous code made little sense.
Best,
Mich
________________________________________
From: e-p...@googlegroups.com [e-p...@googlegroups.com] On Behalf Of Nick G [nick.g...@gmail.com]
Sent: 20 October 2011 06:52
To: E-Prime
Subject: Re: If then and loops

For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

Reply all
Reply to author
Forward
0 new messages