Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript code on more than one line

Status
Not open for further replies.

markprog

Programmer
Oct 4, 2004
12
US
I have a conditional statement that I would like to break into separate lines because it is too long for 1 line.
I know in vbscript that to continue a line you would use the "_" character.
How do you accomplish this in javascript?

If (Condition1) ||
(Condition2) ||
(Condition3) ||
{
statements
}

 
There is no continuation character in Javascript. You can break the if statement into separate ones and set a boolean variable to true or false.

var istrue=false;

if (condition1) istrue=true;
else if (condition2) istrue=true;
else if (condition2) istrue=true;

if (istrue)
{
//what to do if istrue == true
}

Lee
 
And don't forget about the powerful switch statement:

Code:
var the_val = "stuff";

switch (the_val) {
    case "things":
        alert("here I am 1");
        break;
    case "stuff":
        alert("here I am 2");
        break;
    case "crap":
        alert("here I am 3");
        break;
    default:
        break;
}

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Thank you.

On the switch/case statment:

I want to have case #1 with multiple items.
I.E.

switch (myval) {
case "M","P","K":
statement;
break;
case "C","D","L":
statement;
break;
default:
break;
}

is this possible?
 
Code:
switch (myval) {
     case "M":
     case "P":
     case "K":
         statement;
         break;
     case "C":
     case "D":
     case "L":
         statement;
         break;
     default:
         break;
  }

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
thanks chess.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
lol np

(6 characters -- and I meant 5 words? What is this world coming to?)

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top