Showing posts with label For Loop. Show all posts
Showing posts with label For Loop. Show all posts

For Loop using inside of Do While Loop Using in Javascript

for Loop using inside of Do While Loop Using in Javascript 


for loop using inside of the do while loop  in JavaScript.

                       DEMO

           

Javascript Coding

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>for Loop using inside of Do While Loop Using in Javascript </title>
    <script type="text/javascript">       
        do
        {
            var choice = Number(prompt("Enter the Number:"));
            if(isNaN(choice))
            {
                alert('Not a Number');
            }
        }
        while (isNaN(choice))
        {
            for (var i = 0; i < choice; i++)
            {
                document.write(i + "</br>");
               
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" ForeColor="red" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>


Difference Between For Loop and ForEach Loop Using C#



Difference Between For Loop and ForEach Loop



       For Loop        ForEach Loop   
1
For Loop Variable Always int Only.
ForEach Loop Variable Same as Type of Values Under Array
2
For loop Iterates a Statement or a Block of Statements Repeatedly until a Specified Expression Evaluates to False.
For-each loop is used to Iiterate through the Items in Object Collections, List Generic Collections or Array List Collections.
3
For Loops are Faster Than For Each Loop.
For Each Loop are Slower Than For Loop.
4
Need To Loop Bounds (Minimum,Maximum).

Ex:

int count=0;
int j;
for(int i=0;i<=5;i++)
{
   j=count+1;
}

No Need To Loop Bounds Minimum or Maximum.

EX:

int z=0;
int [] a=new int[]      {0,1,2,3,4,5}; 
   foreach(int i in a)
    {
    z=z+1;
    }