yes
2006-08-04 09:25:35
·
answer #1
·
answered by Anry 7
·
0⤊
0⤋
Depends on how you're using it. If you're pulling information from a database, then a while loop is fine because theres always a condtion.
But, if you do something like this:
$name="Joe Blow";
while ($name) {
echo $name;
}
Then it well create an endless loop and freeze up your application.
But if you were to do this:
for ($i=1; $i < 20; $i++) {
echo $name;
}
Then it would loop through 20 times.
I've never used a dowhile loop but it's pretty much the same as a for loop.
2006-08-04 09:30:10
·
answer #2
·
answered by rob 3
·
0⤊
0⤋
No, the statement is incorrect.
Any of the three loops (DO-WHILE, FOR, WHILE) can be used interchangeably. In fact, a FOR loop is really a WHILE loop ... it's simply formatted such that you have a defined region for initializing variables and performing iteration after each pass through the loop.
Both FOR and WHILE loops evaluate the conditional statement(s) prior to entering the loop, and after each repetition thereafter.
DO-WHILE loops do not evaluate the conditional statement(s) prior to entering the loop, but thereafter perform identical to a FOR or WHILE loop, evaluating the conditional statement(s) after each repetition.
The reason for different looping methods is simply that some tasks seem more natural to define with the different approaches. Pick the loop that best illustrates what the code is doing so as to improve readability.
2006-08-04 09:41:37
·
answer #3
·
answered by Arkangyle 4
·
0⤊
0⤋
Depends on the language, but that is the generally accepted practice. Incidentally, in some languages, you can write for loops whose termination conditions don't even depend on the index counter! So theoretically, you could always use a for loop.
2006-08-04 09:27:38
·
answer #4
·
answered by ACDixon 5
·
0⤊
0⤋
no not totally - you can use any loop for any amount of repetition
example using vectors (arrays that you can add/remove elements from)
vectora (3) elements
vectorb (5) elements
"I forget the actually function"
for(int i = 0; i < "number elements(vecotra)"; i++)
{
... statements
}
for(int i = 0; i < "number elements(vecotrb)"; i++)
{
... statements
}
int i = 0
while(i <"...)
{
... statements
i++
}
dowhile(i < "...)
{
... statements
i++
}
see you can use any loop - you just need to know the right setup for each.
2006-08-04 09:31:17
·
answer #5
·
answered by . 3
·
0⤊
0⤋
Sounds good to me :
for l = 1 to 100
....
next l
do
l=l+1
loop until 100
=)
2006-08-04 09:26:50
·
answer #6
·
answered by Special Ed 5
·
0⤊
0⤋
yes
2006-08-04 09:41:14
·
answer #7
·
answered by ZressE 3
·
0⤊
0⤋
yes.
2006-08-04 09:26:29
·
answer #8
·
answered by ? 4
·
0⤊
0⤋
I guess it is.
2006-08-04 09:27:53
·
answer #9
·
answered by I have the Joy of the Lord! 2
·
0⤊
0⤋