473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

One line IF statements

365 100+
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

4 45740
patjones
931 Expert 512MB
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
Dan2kx
365 100+
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
tasawer
106 100+
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
Dan2kx
365 100+
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

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

Similar topics

4
by: Snyke | last post by:
Hi. I have a command line script which works really fine, the only problem is that it take *really* long for the first output to be printed on screen. Since I also get some HTTP headers I'm...
8
by: MrTrix | last post by:
Hello: I'm having a problem formulating the code to execute a multiple line command. I'm trying to execute something like: set rowcount 100000 declare @rowct int select @rowct = 1 while...
3
by: Glenn | last post by:
We want to deploy a change to a database with minimal effort by the users. I see how to open an Access database from the command line, but can you then issue DDL statements through a command line? ...
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
57
by: Mike Malone | last post by:
A colleague of mine is proposing that we use a set of preprocessor definitions to make our C code more readable: #define BEGIN { #define ENG } #define EQ == etc. My initial...
3
by: David N. | last post by:
Hi All, I spent too much time on trying to get the CrLf into a string, which contains embedded SQL statements that can be executed by the SQLClient.SqlCommand. Note that these SQL statements...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
23
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes...
8
by: Jared Wiltshire | last post by:
Hi, I've written the following code to copy one files contents line by line into another file. However I'm a bit dubious about using the infinite loop to do this. ifstream infile("File1.txt");...
3
Logan1337
by: Logan1337 | last post by:
Hi all. I have a method involving several statements, none of which are dependent on any other. Basically I am simply setting a bunch of properties, one after the other, and want to essentially...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.