Closed Thread Icon

Preserved Topic: Does the ELSE always need to be specified (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18087" title="Pages that link to Preserved Topic: Does the ELSE always need to be specified (Page 1 of 1)" rel="nofollow" >Preserved Topic: Does the ELSE always need to be specified <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-20-2001 06:20

When writing an IF ELSE statement, do I always need to specify the ELSE, even if it's empty?

For instance, I have:

<script language=JavaScript type=text/JavaScript>
<!-- Enable Stealth Mode
var homepage=""
if (document.all)
{
document.write("<img src=/images/icons/homepage_icon.gif width=22 height=11 border=0 alt='homepage'> <a href=javascript:void(0); onClick=javascript:this.style.behavior='url(#default#homepage)';this.setHomePage(document.location);>Make this your homepage!<\/a>");
}
else
{
}
// Disable Stealth Mode -->
</script>


Since the ELSE part is empty, can I leave it off without some browsers complaining?



[This message has been edited by Pugzly (edited 06-20-2001).]

kars10
Bipolar (III) Inmate

From: Europe
Insane since: Mar 2001

posted posted 06-20-2001 06:29

jope.

u know, that you don;t really need an else, if there is only one if-conditon, right?
( I mean, you are checking for a condition. (simplified):
If true, change it, if not, leave it.
That can be shortened to:
If true, change it.
That's why you don't even need an else. And the browser won't bother you.)
(well, shouldn;t... let's see what the others say )
K10


only change remains

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-20-2001 07:53

ELSE part (if empty) is not needed...

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-20-2001 14:36

Thanks, guys. One of these days, I might actually understand this stuff.....

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-20-2001 19:13

Indenting your code may help :P

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-20-2001 20:18

Yeah, think of "else" as something that you're allowed to *add* to an if statement, not something that you're allowed to leave out. It's an accessory, sorta.

« BackwardsOnwards »

Show Forum Drop Down Menu