If Else - Complete Study - SWiSHMax Tutorials
 
  Buy Ebooks, Video Games, DVDs, Electronics and more !
Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads Make Money Online Blog . Free Image and Photo Sharing and Hosting

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Free image hosting
   Web Design Pakistan
   Swish Templates
   SWiSH Climax
   Talkfreelance Community
   Template Desire
   Lite boards
   Script Sector
   GimpTalk
   13dots
   Idea Designs
   PHP Cafe
   Sposatoettore
   Free swishmax templates
   Swishzone

Manage your site with Flax Article Content Management System
If Else - Complete Study
Category : SWiSHMax | Level : Intermediate | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

Understanding if Else Structure
---------------------------------------

The IF Structure
The [b]if
structure is used when you want to perform a specific/indicated action.
It is activated when the condition becomes true. For example you have assigned a value to variable x=0 and you use if strutcutre like this

if(x==10) {
perform any action;
}

in this case this statement will be activated when the value of x becomes 10. If the
value of x becomes 10 it means the conidtion is true.
Basically we use it for comparing two or more statements.

How to use IF Structure
-------------------------------
It is very simple to use, for example you are moving a sprite on x-axis and you are continously
increasing its _X position. e.g the initial _X of your sprite was 0 and you want that when it reaches 200
then you want your sprite go back on _x=0 and start. What you will do is

Example 1
-------------
1. Make a rectangle and convert it to sprite. Rename "sprite" as "bar". From transform tab place it on X=0
2. On the frame number 1 paste this code

CODE


[color=blue]

onEnterFrame() {

   bar._X+=1;

   if(bar._X==100){

     bar._X=0;

   }

}

[/color]



Now in this line bar._X+=1; we are only changing the position continously but in code


if(bar._X==100){
bar._X=0;
}


we are comparing the X with 100, here we have stated that if X reaches 100 then again assign a new value to X which is 0.

else-if Structure
The [b]else
is used when you also want to perform an action when the statement is flase. For example in
the above Example we have only used if structure. Ok now I will make the same example using if else

Example 2
-------------
1. Make a rectangle and convert to sprite. Rename "sprite" as "bar". Place it on X=0
2. On the frame number 1 paste this code


onEnterFrame() {
if(bar._X==100){
bar._X=0;
} else bar._X+=1;
}


Now this example will also perform the same action as Example 1. But the only difference is that we
have used if else.
Concentrate on the code, you have seen when the movie starts the bar._x=0 because we have palced it at 0, it means the if is activated.

This is how if and if else statements works. You can make as many comparisons you want. In the above example 2 we have made only one if structure

What is a typical else if
The word Typical in this case, is in the sense, you might have seen codes like this

CODE


[color=blue]

on (release) {

   if(inputVar=="Ali"){

       dynVar="Administrator";

   } else if(inputVar=="Charly"){

       dynVar="Moderator";

   } else if(inputVar=="rob88wells"){

       dynVar="Co-Admin";

   } else if(inputVar=="johno"){

       dynVar="Member";

   } else dynVar="Guest";

}

[/color]



In the above code you have made one input box and its variable name is inputVar and one
dynamic text box and its variable name is dynVar. Made on buttons and on its action we used
the aboce code. Now this code will check the string (means the text you write) if it is "Ali"
then in Dynamic TEXT box (dynVar) it will display "Administrator", the same if the string is
"Charly" it will display "Moderator". After comparing all else if structure, if there are no
matches then it will display "Guest" in the dynamic text box.

So now you can make and use else if and simple if structures.
Ok - here is the list of operators you will be using in these structures.

Operator Description
< relational less than
<= relational less than or equal to
> relational greater than
>= relational greter than or equal to
= assignment operator (for assignin any value to any variable/expression)
== is equal to
!= is not equal to

&& logial AND
|| logical OR

some other operator which may be used in other codings.
+= addition asignment
-= subtraction asignment
*= multiplication asignment
+= division asignment

I think its enough to understand for an intermediate or basic level user.
If you have any further questions, feel free to ask.

best regards
- Ali Roman...


© 2002-2005 Flaxweb Network | Article Manager | Gimp Tutorials Library | RAD C++ Library | Free C/C++ Sourcecode |
Sites of interest : Web Design Blog | Swish Templates | Swishmax Ebook | Photoshop Templates | Gimp Tutorials | Text Forum | Make Money Online