Jump to content

How to use if else

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
toxifyshadow

toxifyshadow

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
Using if else can be very helpful.
Here's basically what it does and how it works.

First we create the if part.
If the if is true then the code inside will be executed.
This looks like:

/*Define if, and give it a value.

if that value is true than the code will be executed

*/

if(x+a=y)

//here is your code to be used

{

document.write("This value is true")

}

Now, if your if is false, nothing is going to show up. So we can add else.
Else, unlike if, doesn't need a value, so it just looks like:

else

{

document.write("The value was wrong")

}

Now there will always be something showing up on your page.
If you want more than one value you can simply add more else:

else(s+7=9)

{

document.write("This is the extra else example")

}

So you could have a full code like:

if(x+a=y)

{

document.write("Value 1 is true")

}

else(x+a<y)

{

document.write("Value 2 is true")

}

else

{

document.write("All values are false")





This is my first tutorial and I hope you enjoyed this.

Edited by toxifyshadow, 18 March 2010 - 06:04 PM.
Added more


#2
James.H

James.H

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 866 posts
Do provide screenshots or extend on it a little but not bad tut

#3
toxifyshadow

toxifyshadow

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
Sorry, I use a Wii. I don't have a computer yet so I can't upload, download, or take screenshots.

#4
Irfan_A

Irfan_A

    Programmer

  • Members
  • PipPipPipPip
  • 186 posts
Maybe better you make and post tutorial at midnight.
Keep up good work and add more features like advice from James.
That is your first tutorial, good, i wait your other tutorials about JavaScript again or others in future.

(oh, i never post tutorial in CC up to now, i will do it soon if i have enough time...)
nomainwin : open "CodeCall" for dialog_nf_modal as #whileTrue : wait

#5
toxifyshadow

toxifyshadow

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
Thanks. I'm going to make another one sometime, but for now I want to add on to this one.