# Programming Question

Status
Not open for further replies.

#### Wjs

##### New Member
1. Explain the three statements needed to to formulate a for loop.

1. Something to do before starting

2. A test to perform as long as it’s true, keep looping

3. Something to do after each loop (increase a variable)

#### Pommie

##### Well-Known Member
That is correct for C.
I.E. for (i=1;i<8;i++)
OR for (i=1;i<128 && !done;i*=2)

However for Basic the test (2) is automatic.
I.E. for 1=1 to 10

Mike.

#### Daniel Wood

##### Member
The first answer seems a little vague to me.
If you're doing this as part of a test, I think you would need to talk about the initialisation or setting the variable to be used in the second or third section to get the marks.

#### Nigel Goodwin

##### Super Moderator
The first answer seems a little vague to me.
If you're doing this as part of a test, I think you would need to talk about the initialisation or setting the variable to be used in the second or third section to get the marks.
I would imagine it's a multiple choice question?, so 2 would be correct.

#### Daniel Wood

##### Member
Who knows.. Maybe Wjs can enlighten us

The question asks to explain, so I think the question requires three separate answers.
If this is the case, they are all correct, but they could be worded better.

#### Dr_Doggy

##### Well-Known Member
I think thats right.... Explain the three statements!! .... " for( 1 ; 2 ; 3 ) "

but whats wrong with answer 1&3
1 happens prior to loop (before starting)
and
3 happens at the end of each loop

#### KeepItSimpleStupid

##### Well-Known Member
I think the point is to know the difference between a FOR and a WHILE loop. the HINT is the WHILE loop will always execute once.

Consider
x=4
While x<=3
Print x
x=x+1
Next

and

For x = 0 to -1 step 1
print x
Next

#### NorthGuy

##### Well-Known Member
C:
for (a; b; c) {
d;
}
is equivalent to

C:
a;
while (b) {
d;
c;
}
There are some differences, e.g. the use of "continue", but it's probably not important here.

#### KeepItSimpleStupid

##### New Member
(I think the OP should clarify the question, but, til then...)
It seems that OP gave the three statements as answer to the question "what are the three etc?" and that his post is just (unwarranted) self-doubt

#### DerStrom8

##### Super Moderator
His question was very poorly worded. I think he should re-ask but make his question MUCH more clear.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
The question is right...

Question : - Explain the three statements needed to to formulate a for loop.

1. Something to do before starting

2. A test to perform as long as it’s true, keep looping

3. Something to do after each loop (increase a variable)

We need to agree or disagree with WJS's answers....