Using a Do/While Loop to Reverse a Text String : JavaScript DHTML examples (example source code) » Language Basics » While

JavaScript DHTML
C++
Java Products
Java Articles
JavaScript DHTML Home  »   Language Basics   » [  While  ]   
 



Using a Do/While Loop to Reverse a Text String

Please note that some example is only working under IE or Firefox.

/*

Learn How to Program Using Any Web Browser
by Harold Davis 

Apress CopyRight 2004

ISBN: 1590591135
*/
<HTML>
<BODY>
<H1>
<SCRIPT
      var newString = ""
      var theString = prompt("Enter a string for reversal","")
      var counter = theString.length; 
      do 
      
        newString += theString.substring(counter-1, counter)
        counter--; 
      
      while (counter > )
      document.write(theString + " reversed is " + newString + "!")
   </SCRIPT>
</H1>
</BODY>
</HTML>
Related examples in the same category
1.   A While Loop That Decrements from 10 to 1
2.  While loop
3.  Do while loop
4.  Using the while Loop in JavaScript
5.  The do..while Statement Ensures at Least One Iteration
6.  The while Statement
7.  Loop in while
8.  While loop test








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.