HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 14th, 2000, 05:31 AM
peterbe peterbe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 58 peterbe User rank is Private First Class (20 - 50 Reputation Level)peterbe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
// replace swedish chars with HTML ones.
function sweToHTML (context) {
var breaking=0;
while (breaking < 1)
{
breaking++;
if (context = context.replace("å","å"))
{ breaking=0; }
if (context = context.replace("Å","Å"))
{ breaking=0; }
if (context = context.replace("ä","ä"))
{ breaking=0; }
if (context = context.replace("Ä","Ä"))
{ breaking=0; }
if (context = context.replace("ö","ö"))
{ breaking=0; }
if (context = context.replace("Ö","Ö"))
{ breaking=0; }

}
return (context);
}
[/code]

{ Note! context.replace("Ö","Ö")) means, replace swedish character with a HTML one }
First, the "breaker" is set to zero outside the loop. And if var breaking is less than 1, do the loop.
In the loop, if a string.replace() is made, then reset the var breaking again, so that the loop happens again.
If no changes are made, then var breaking is incremented once and once again, to quit the loop.
Either I get an infinite loop of one that doesn't do anything.

Please help

------------------

¬ peterbe.com ¬

[This message has been edited by peterbe (edited August 14, 2000).]

Reply With Quote
  #2  
Old August 15th, 2000, 11:23 AM
peterbe peterbe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 58 peterbe User rank is Private First Class (20 - 50 Reputation Level)peterbe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
SOLVED IT!


<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
function sweToHTML (context,onoff) {
swechars = new Array("å","Å","ä","Ä","ö","Ö");
HTMLchars = new Array("å","Å","ä","Ä","ö","Ö");
if (onoff < 0)
{
alert("nntreverse order or arraystnn");
}

var limit=0;
while (limit < 1)
{
limit=1;
for (i=0; i<swechars.length; i++)
{
if (context.match(swechars[i]))
{ context = context.replace(swechars[i],HTMLchars[i]); limit=0; }
}
}

return (context);
}
[/code]



------------------

¬ peterbe.com ¬

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > Why doesn't this while loop work?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT