Home   News  Product reviews  Website reviews  Forums   Competitions  Subscribe 


Web Building >> Web design & build
 |  Print Topic
Jump to first unread post. Pages: 1
palomares
regular


Reg'd: Thu
Posts: 36
Is there the equivalent of Goto in Javascript?
      #171308 - Fri Mar 18 2005 08:55 PM

Hi,

I am a complete beginner ,trying to learn some Javascript. I was asking myself if there is a command , like the Goto command in Basic. I remember:

10 bla bla
20 bla bla
30 if (Something) goto 10

Or if this is more helpful:



var number ;

number = prompt("Please enter a number"," ");

number = parseInt(number)

if (isNaN(number))
{
document.write("This is not a number<br />");
document.write(" Please try again!");

}
else

{
var result ;

result = 2*number ;

document.write("The number times two is = "+result);
}


Just after the

"Please try again",..., I'd like to make it return to the first line, therefore asking the user to add another input,...

Could anybody point me in the right direction of a command which would do this?
Many Thanks


Post Extras: Print Post   Remind Me!   Notify Moderator  
paul_lomax



Reg'd: Wed
Posts: 1661
Loc: London, England
Re: Is there the equivalent of Goto in Javascript? [Re: palomares]
      #171398 - Sat Mar 19 2005 03:24 AM

'goto' is considered 'evil' in every progamming language other than Basic (very long story as to why...).. in this case you actually want to do a 'while' loop. It returns to the top of the {} as long as the condition remains true.
var number;
number = prompt("Please enter a number"," ");
number = parseInt(number)

while (isNaN(number))
{
document.write("This is not a number
");
document.write(" Please try again!");
}

var result ;
result = 2*number ;

document.write("The number times two is = "+result);




Paul Lomax
Internet Technology Manager
IPC Country and Leisure Media
- www.ipcmedia.com

Pick Me Up magazine - Real life as you've never seen it before!


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1

Rate this topic

Jump to


Extra information
0 registered and 0 anonymous users are browsing this forum.

Moderator:  putasolutions, Joe_London, greysts, bricat, Nanook, Hello_There, John_McKenna, Mouse, TheFatControlleR 


Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      Mark-up is enabled

Rating:
Topic views: 292

Contact Us | Privacy statement Main website