IF ELSE Indenting

Microsoft Windows xp professional w/serv...
December 12, 2009 at 02:17:38
Specs: Windows XP
I hope this isn't a double post. I don't know where my first attempt to post went.

I read a post in another forum that said IF ELSE statements had to be in this exact format to work correctly:

FORMAT-1:
IF <statement> (
<statement>
<statement>
) ELSE (
<statement>
<statement>
)

Is that correct? How about this format:
(periods represent spaces for indents)

FORMAT-2:
IF <statement> (
...<statement>
...<statement>
) ELSE (
...<statement>
...<statement>
)

or how about this format:

FORMAT-3:
IF <statement> (
...<statement>
...<statement>
...) ELSE (
...<statement>
...<statement>
...)

Thanks,
Sky


See More: IF ELSE Indenting

Report •


#1
December 12, 2009 at 03:22:19
Yes, all three formats will work. For best readability I prefer
the second option. The third option doesn't make it clear
where the else line is, because it's at the same indentation
level as the rest of the block.

The requirement is that the opening brackets must be on the
same line as the IF and ELSE statements, and the ELSE
statement must be on the same line as the preceding closing
bracket. That's all.

So the following will NOT work:

IF <statement> (
   <statement>
   <statement>
)
ELSE (
   <statement>
   <statement>
)

This is documented in the help available when you type

IF /?


Report •

#2
December 12, 2009 at 05:35:24
You could also use 1 liners if you need to. i.e:-

if %number% == '3' (echo Number 3) else (echo Error)


Report •

#3
December 12, 2009 at 12:20:48
=====
klint said:
Yes, all three formats will work. .....snip.....

Thanks a lot! I think I understand indenting a lot better now. BTW, how did you format your response to allow leading spaces to show the indenting? (leading spaces were compressed when I tried my post)

Sky

=====

lee123abc said:
You could also use 1 liners if you need to. .....snip.....

Thanks for your input.
Sky
=====


Report •

Related Solutions

#4
December 13, 2009 at 02:00:03
The short answer to preserving spacing is to use 'pre tags'.

Example:

if bla (
  ) else (
  no bla
)

Be sure to END the tags so you don't trash the whole page.


=====================================
Helping others achieve escape felicity

M2


Report •

#5
December 13, 2009 at 02:19:35
If you don't want to type pre, just press the "pre" button over the text box.

Report •

#6
December 13, 2009 at 11:05:17
This is a test to preserve spacing:

If <condition> (
     <statement>
) else (
     <statement>
)

It works! Thanks Mechanix2go and klint.
And thanks klint for pointing out the "pre" button as I would have been lost without that tip.

Sky


Report •

#7
December 13, 2009 at 19:56:49
LOL I don't see any pre button.

But I have a script which pastes any given file and adds tags.


=====================================
Helping others achieve escape felicity

M2


Report •

#8
December 14, 2009 at 02:08:41
M2, they don't look like buttons, but you should see five little icons above the text box in which you type your reply. They are B (bold), I (italic), S (strikeout), globe and chain (hyperlink), and finally,
pre
(the one we are talking about!)

Report •

#9
December 14, 2009 at 03:17:40
Hi klint,

Thanks. No such thing here. They probably load from one of the crapware sites I have blocked in HOSTS.


=====================================
Helping others achieve escape felicity

M2


Report •

#10
December 14, 2009 at 04:29:26
Have you blocked static.computing.net? I very much doubt it: this is the hostname where the stylesheet and many other essential elements of the website are kept.

The icons are http://static.computing.net/img/bol... etc.

etc.

Do you not see the text area like this? Do you not have these little icons (to the right of the "Comments:" label) as shown in the linked picture?

(Edited to correct image url)


Report •

#11
December 14, 2009 at 04:55:54
"Have you blocked static.computing.net?"

yep

There's a whole lot of clutter I don't see.

Don't need no CSS, frames, animated gifs, intellitext, kids, dogs, warm beer...


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question