By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,480 Members | 2,953 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,480 IT Pros & Developers. It's quick & easy.

One line IF statements

100+
P: 365
Just a quick question....
Not really a fundamental one, just a general yes or no...

ya know how ifs work...
Expand|Select|Wrap|Line Numbers
  1. If Something = True Then 
  2.      Do something
  3. End if
Or
Expand|Select|Wrap|Line Numbers
  1. If Something = True Then Do something
is it possible to construct a "queue" of things to do in a single line?
for example
Expand|Select|Wrap|Line Numbers
  1. If Something = True Then Do something; Do something else
Just curious, i often prefer the one line IF for short IF's (i think it looks tidier?)

Dan
Mar 8 '10 #1

✓ answered by patjones

Dan -

It's possible, by separating the statements to be executed with a ":" -

Expand|Select|Wrap|Line Numbers
  1. If some condition true Then statement1 : statement2 : ... : statementN

But this is a good idea only for simple If constructs. For anything with more than one or two statements it is usually more readable to use the regular "block" form -

Expand|Select|Wrap|Line Numbers
  1. If some condition true Then
  2.      statement1
  3.      statement2
  4.      ...
  5.      statementN
  6. End If
  7.  

Pat

Share this Question
Share on Google+
4 Replies


patjones
Expert 100+
P: 931
Dan -

It's possible, by separating the statements to be executed with a ":" -

Expand|Select|Wrap|Line Numbers
  1. If some condition true Then statement1 : statement2 : ... : statementN

But this is a good idea only for simple If constructs. For anything with more than one or two statements it is usually more readable to use the regular "block" form -

Expand|Select|Wrap|Line Numbers
  1. If some condition true Then
  2.      statement1
  3.      statement2
  4.      ...
  5.      statementN
  6. End If
  7.  

Pat
Mar 8 '10 #2

100+
P: 365
oh yeah i agree, complex things needthe full construct.

i just found my self writing two almost identical lines which were very basic and thought.... hmmmmmmmmmmmm... i wonder IF

Cheers
Mar 8 '10 #3

100+
P: 106
Hi,

have you considered using SELECT CASE?

Expand|Select|Wrap|Line Numbers
  1. SELECT CASE x
  2.  Case x=1st option
  3.  Do Something
  4.  
  5.  Case x=2nd Option
  6.  Do Something
  7.  
  8. etc.
  9.  
  10. END SELECT
  11.  
Mar 9 '10 #4

100+
P: 365
I use select case statements regularly, my needs here are just to tidy up small simple statements, like procedure calls etc.

Dan
Mar 10 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.