Actually these are all loops to be used in different situations.
There are no considerable performance diffrence between these. All when compiled achieves almost same form. But some common strategical used are described below. No need to adhere to these u can use whichever u think appropriate for situation and moreover code must be easily understanadable
For Next loops are used when u know the limits of iterating variable and iterating variable is a numeric value
Do While
eg Do While Not EOF
Load(%26lt;some data%26gt;) to GridView
Loop
Do Until are usually used to achieve a target.
eg Do Until Not EOF
find(%26lt;something%26gt;)
Loop
What is the advantages and disadvantages of the For Next Loops, Do While Loops, and finally Do Until Loops?
i dont know what language it is
so try www.wikipwedia.com
as far as i know
for ,while loop:
the condition needs to be true everytime
do while loop:
the statements are executed once even if the condition is false
Reply:Every one of these have thier own advantages and disadvantages
Reply:For Next loops contain an incremented subscript. You set the start value, the increment and the terminating test which may or may not relate to the subscript. Though it usually does.
Do While loops contain no subscript they just loop until the test is negative. The condition is tested first so this loop may never be executed.
Do Until loops also contain no subscript. They also just loop but this time until the test is positive.
A Do Until loop test is at the end of the loop so the loop will always execute at least once.
Reply:The only thing that I can think of is that the advantages could be you can easily loop through a specified object and find what you want. The only disadvantage that I see would be if you are looping through a long item, it may slow your system down temporarily. However, if you are only looking for one item that matches your criteria, you could probably add an exit loop to your loop.
Reply:For loops are good at incrementing a variable while performing a block of code. For example loading the elements of an array
Do until %26amp; Do while are nearly identical. Basicaly they repeate a block of code until a condition is either true or false.
c++ only has a while %26amp; do while option. While loops repeate a block of code "while" a condition is true. There for the loop may exicute 0 or more times. The do while loop is the same as a while loop with one exception, it always exicutes the block of code at least once. So, in conclusion-
For Loop = loop through a preset number pattern.
While Loop = loop only if a condition is true.
Do While Loop = loop at least once and until a condition is false.
Reply:'for' loops are generally for a set number of times...
for (i=0; i %26lt; 10; i++) {
do this 10 times
}
... or for iterating over something...
for each (array) {
do something with each member
}
'while' loops (and their siblings, 'until', which just means 'while not') are usually more for manipulating things inside the loops...
while (a is too big) {
make a smaller
}
This *won't* do anything if a is already small. If you *always* want to make a smaller, even if it's small already, you can do this...
do {
make a smaller
} until (a is small enough)
Reply:in for and while loop pre condition check
in do while post condition check
in for loop
for(%26lt;initialisation%26gt;;%26lt;condition%26gt;;%26lt;manipu...
for example
for(i=0;i%26lt;n;i++) (i should be less than 10 that is i=n-1)
in while
while(%26lt;Condition%26gt;)
{
}
example
while(i%26lt;n)
i++;
in do
{ i++;
}while(i%26lt;n) where i become i=n but in for and while i in a loop remane i=n-1 as it become i=n the loop be stoped
i++;
visual arts
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment