Lost Password?

  #1 (permalink)  
Old 12-08-2006, 05:35 AM
TcM's Avatar   
TcM TcM is online now
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 7,223
Rep Power: 66
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default JavaScript:Tutorial, Break Out Of Loops

Introduction:-
To understand this tutorial make sure that before you see this tutorial JavaScript :Tutorial, Loops and JavaScript :Tutorial, Your First Game! here we will elaborate a little more on these!

Explanation:-
In this tutorial the Explanation goes before the code too.

Code:
while (something)
{
do something else
if (something(while looping))
{
end the loop
}
I hope this explained the basic concept on how to break out of loops

Solution:-
Now here are some practical codes! Here

Code:
<SCRIPT LANGUAGE="JavaScript">
var usrno = 0;
while (usrno!=50)
{
usrno = window.prompt('Guess the number, enter end to finish',0);
if (usrno=='end')
{
alert('Game Ended');
break;
}
if (usrno<50)
{
alert('too low');
}
if (usrno>50)
{
alert('too high');
}
}
</SCRIPT>
Explanation Of Code:-
Code:
usrno = window.prompt('Guess the number, enter end to finish',0);
if (usrno=='end')
{
alert('Game Ended');
break;
}
This is the most important code. Here we are promoting the user ( see this tutorial JavaScript :Tutorial, Prompt ) and asking him to enter a number but if he instead writes 'end' without the ' ' the game will display an alert and we will break out of the loop, because of the 'break;' command!!

A Preview:-


Conclusion:-
As Always Feedback is welcome and the full source is attached!!
Attached Files To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Othello program!! 24 hours left! siren C and C++ 1 06-14-2007 11:18 AM
MySQL Loops reachpradeep Database & Database Programming 0 03-04-2007 09:12 AM
JavaScript:Tutorial, Loops TcM Javascript 4 12-13-2006 08:53 AM
Loops Sionofdarkness C and C++ 7 07-28-2006 07:53 PM


All times are GMT -5. The time now is 03:16 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 65%

Ads