Tuesday, October 21, 2014

IF condition statement in javascript , Switch case statement in javascript

  • CONDITIONAL STATEMENTS:
  • Conditional statements in JavaScript are used to perform different actions based on different conditions.
  • Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
  • In JavaScript we have the following conditional statements:
  • if statement - use this statement if you want to execute some code    

                       only if a specified condition is true

  • if...else statement - use this statement if you want to execute some code if the condition is true and another code if the condition is false
  • if...else if....else statement - use this statement if you want to select

                                             one of many blocks of code to be executed

  • switch statement - use this statement if you want to select one of

                               many blocks of code to be executed

IF STATEMENT:

  • You should use if statement if you want to execute some code only if a specified condition is true.

Syntax:
        If <condition>
{
JavaScript code executed if condition becomes true.
}

Example:
<script language = "javascript">
var x = 5,y=6;
if (x>y)
{
document.write(' x is greater');
}
</script>

IF...ELSE STATEMENT:

  • If you want to execute some code if a condition is true and another code if the condition is not true, use if....else statement.

Syntax:

            if (condition) 
            { 
Code to be executed if condition is true 
            } 
            else 
            { 
Code to be executed if condition is not true
            } 

 

Example:
<script language = "javascript">
x = 5;
y = 6;
if (x > y)
{
document.write('x is greater');
}
else
{
document.write('y is greater');
}
</script>

IF…ELSE IF…ELSE STATEMENT:
  • It is used when user have two or more condition to check for execution of code.

Syntax:
          if <condition1>
{
          Code if condition 1 is true;
}
else if <condition2>
{
          Code if condition 2 is true;
}
else
{
          Code if no condition becomes true;
}

Example:
            <script language = "javascript">
                        x=5;
     y=6;
     z=7;
     if(x>y && x>z)
     {
                 document.write('x is greater');
     }
     else if(y>x && y>z)
     {
                 document.write('y is greater');
     }
     else
     {
                 document.write('z is greater');
     }
            </script>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


SWITCH STATEMENT:

  • use the switch statement to select one of many blocks of code to be executed

 

Syntax:
        switch (n)

          { 
    case 1: 
               Execute code block 1 
               break;     
    case 2: 
               Execute code block 2 
               break; 
    default: 
               Code to be executed if n is 
               Different from case 1 and 2
           } 
 


  • First we have a single expression n (most often a variable), that is evaluated once.

 

  • The value of the expression is then compared with the values for each case in the structure.
  • If there is a match, the block of code associated with that case is executed.

 

  • Use break to prevent the code from running into the next case automatically.

12 comments:

SURAJ said...

Thanks for your information.
https://livescorecri.blogspot.com/p/blog-page_5.html
https://www.chemistrypage.in/cbse-class-12th-chemistry-question-paper-analysis-set-1/

php projects free download zip said...

Thanks for sharing this wonderful and value able piece of information
if u want to see more php project and free download source code click here

dhinesh said...

Thank you so much for sharing this awesome post, This was so good to read and useful to gain my knowledge as updated one, keep blogging
Full Stack Training in Chennai | Certification | Online Training Course | Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Training in Pune | Certification | Online Training Course | Full Stack Training | Certification | Full Stack Online Training Course

worldw MOHAMED said...

Lumela motho e mong le e mong,
Lebitso la ka ke Mong, Rugare Sim. Ke lula Holland 'me ke motho ea thabileng kajeno? mme ke ile ka tsebisa nna hore moreki ofe kapa ofe ea mpholosang le ba lelapa la ka maemong a rona a mabe, ke tla romella motho e mong le e mong ea batlang mokoloto ho eena, o natefisitse nna le ba lelapa la ka, ke hloka mokoloto oa € 300,000.00 ho qala bophelo ba ka hohle ka ha ke le Ntate a le mong le bana ba 2 ke kopane le mokoloto eane ea ts'epahalang le Allah ea nthusitseng ka mokoloto oa € 300,000.00, ke monna ea tšabang Allah, ha o hloka mokoloto mme o tla lefa mokoloto ka kopo ikopanye le eena hore o mo joetse hore (Mong, Rugare Sim) o tla u romela ho eena. Ikopanye le Mong, Mohamed Careen ka imeile: (arabloanfirmslements@gmail.com)


MOTLATSI OA HO BUA KA KHOTSO
Lebitso la pele......
Lebitso le mahareng.....
2) Bong: .........
3) Chelete ea mokoloto e ea hlokahala: .........
4) Nako ea mokoloto: .........
5) Naha: .........
6) Aterese ea lapeng: .........
7) Palo ea selefouno: .........
8) Aterese ea lengolo-tsoibila ..........
9) Moputso oa khoeli le khoeli: ………………… ..
10) Mosebetsi: ………………………
11) Ke sebaka sefe sa marang-rang seo u se entseng mona mabapi le ...
Thanks and Best Likhau.
Email (arabloanfirmserves@gmail.com)

worldw MOHAMED said...

Lumela motho e mong le e mong,
Lebitso la ka ke Mong, Rugare Sim. Ke lula Holland 'me ke motho ea thabileng kajeno? mme ke ile ka tsebisa nna hore moreki ofe kapa ofe ea mpholosang le ba lelapa la ka maemong a rona a mabe, ke tla romella motho e mong le e mong ea batlang mokoloto ho eena, o natefisitse nna le ba lelapa la ka, ke hloka mokoloto oa € 300,000.00 ho qala bophelo ba ka hohle ka ha ke le Ntate a le mong le bana ba 2 ke kopane le mokoloto eane ea ts'epahalang le Allah ea nthusitseng ka mokoloto oa € 300,000.00, ke monna ea tšabang Allah, ha o hloka mokoloto mme o tla lefa mokoloto ka kopo ikopanye le eena hore o mo joetse hore (Mong, Rugare Sim) o tla u romela ho eena. Ikopanye le Mong, Mohamed Careen ka imeile: (arabloanfirmslements@gmail.com)


MOTLATSI OA HO BUA KA KHOTSO
Lebitso la pele......
Lebitso le mahareng.....
2) Bong: .........
3) Chelete ea mokoloto e ea hlokahala: .........
4) Nako ea mokoloto: .........
5) Naha: .........
6) Aterese ea lapeng: .........
7) Palo ea selefouno: .........
8) Aterese ea lengolo-tsoibila ..........
9) Moputso oa khoeli le khoeli: ………………… ..
10) Mosebetsi: ………………………
11) Ke sebaka sefe sa marang-rang seo u se entseng mona mabapi le ...
Thanks and Best Likhau.
Email (arabloanfirmserves@gmail.com)





Hello Everybody,
My name is Ahmad Asnul Brunei, I contacted Mr Osman Loan Firm for a business loan amount of $250,000, Then i was told about the step of approving my requested loan amount, after taking the risk again because i was so much desperate of setting up a business to my greatest surprise, the loan amount was credited to my bank account within 24 banking hours without any stress of getting my loan. I was surprise because i was first fall a victim of scam! If you are interested of securing any loan amount & you are located in any country, I'll advise you can contact Mr Osman Loan Firm via email osmanloanserves@gmail.com

LOAN APPLICATION INFORMATION FORM
First name......
Middle name.....
2) Gender:.........
3) Loan Amount Needed:.........
4) Loan Duration:.........
5) Country:.........
6) Home Address:.........
7) Mobile Number:.........
8) Email address..........
9) Monthly Income:.....................
10) Occupation:...........................
11)Which site did you here about us.....................
Thanks and Best Regards.
Derek Email osmanloanserves@gmail.com

Unknown said...

Na o hloka mokoloto o potlakileng? Re fana ka mekoloto ho batho ba nang le thahasello ba batlang kalimo ka tumelo e ntle. Re fana ka lits'ebeletso tse fapaneng tsa lichelete: moralo oa khoebo, lichelete tsa khoebo le nts'etsopele, mekoloto ea ntlo le mekoloto ea ntlo, mekoloto ea kopanyo ea mekoloto, mekoloto ea khoebo, mekoloto ea poraefete, kalimo ea baithuti, litefiso tse fokolitsoeng tsa sekhahla ka 3%.
Ka kopo ikopanye le rona bakeng sa mokoloto oa hau o sirelelitsoeng le o sa sirelletsoang Bakhethoa ba nang le thahasello ba lokela ho ikopanya le rona ka lengolo tsoibila: bryanstefanloanfirm@outlook.com kapa bryanstefanloanfirm@gmail.com

Ikopanye ka WhatsApp: + 919654763221
Ka boikokobetso,
Monghali Bryan Stefan

Bryan Stefan Loan Firm said...

Sena ke ho u tsebisa hore re fana ka mefuta eohle ea Mokoloto (Khoebo, Motho, Kopanyo, Koloi, Matsete, jj) @ 3% sekhahla sa selemo Na o hloka mokoloto mme o hanngoe ke banka ea hau ka lebaka la mokoloto o mobe? O na le likoloto tse sa lefelloeng kapa mokoloto? Re potlakile ebile rea tšepahala ebile botšepehi ke lentsoe la rona la ho shebella.

TLATSANG FOMO EA KOPO
Lebitso la hau ka botlalo: Aterese: Bong: Chelete e Hlokahalang: Nako: Naha: Mosebetsi: Nomoro ea mohala: Morero oa kalimo:

Litumeliso tse mofuthu,
Bryan Stefan (CEO)
Re romelle molaetsa: bryanstefanloanfirm@gmail.com kapa
whatsapp: + 919654763221
Bryan Stefan (CEO)
Khampani ea Bryan Investment

Bryan Stefan Loan Firm said...

Sena ke ho u tsebisa hore re fana ka mefuta eohle ea Mokoloto (Khoebo, Motho, Kopanyo, Koloi, Matsete, jj) @ 3% sekhahla sa selemo Na o hloka mokoloto mme o hanngoe ke banka ea hau ka lebaka la mokoloto o mobe? O na le likoloto tse sa lefelloeng kapa mokoloto? Re potlakile ebile rea tšepahala ebile botšepehi ke lentsoe la rona la ho shebella.

TLATSANG FOMO EA KOPO
Lebitso la hau ka botlalo: Aterese: Bong: Chelete e Hlokahalang: Nako: Naha: Mosebetsi: Nomoro ea mohala: Morero oa kalimo:

Litumeliso tse mofuthu,
Bryan Stefan (CEO)
Re romelle molaetsa: bryanstefanloanfirm@gmail.com kapa
whatsapp: + 919654763221
Bryan Stefan (CEO)
Khampani ea Bryan Investment

Blogger said...

PHP Course in Delhi

Assignment Writing Help Online - Case Study Solutions said...

Thanks for Sharing This Article. Research Proposal Help is a website that allows you to Online Assignment Help online. Easily to write, Assignment Help Online with trained male and female teachers in Online Classes For Indian Students..

Ian Bell said...
This comment has been removed by the author.
Essay typer said...

great article Admission Essay Help Toronto