Programming Question

Status
Not open for further replies.

Wjs

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

  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)
I have answer the above question but don't know is correct anot. Please advise
 
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.
 
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.
 
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.
 
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.
 
The way I read it....... Explain the three statements!! .... " for( 1 ; 2 ; 3 ) " Therefore only answer 2 is correct...
 
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
 
Oh I see!!! 1) start variable statement ... 2) while true statement... and 3) conditional loop statement ...

The Tutor just wants you to explain each element!!!
 
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
 
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.
 
(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
 
His question was very poorly worded. I think he should re-ask but make his question MUCH more clear.
 
The question is right...

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

WJS has answered..
  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)
WJS asks : -- Are my answers near the mark??

We need to agree or disagree with WJS's answers....
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…