I have a question on an assignment that has me confused. The question is how many times does the following loop execute?

For I = 1 to 10
PRINT I
End For (I)

Now I am not sure if this is a trick question or not. I do not see a loop in the above statement, I = 1 to 10, print I would display 1,2,3,4,5,6,7,8,9,10 and then end. I do not see a loop.

Am I out in left field?? Any assistance would be greatly appreciated.

I thought I knew what a loop was, I must have really mixed a few of these lessons up.

So then the

For I = 1 to 10
PRINT I
End For (I)

Does in fact state an actual loop and the 1 to 10 is the times the loop will execute? So it will loop 10 times?

>I have a question on an assignment that has me confused.
And confused you should be, because the question is ambiguous.

>The question is how many times does the following loop execute?
The real question is what language is that? If it's pseudocode that follows C++ rules, the loop will execute 9 times because 1 TO 10 probably denotes a half-open range [1,10) where the 10 is excluded (as is the convention in C++). So the output would be:

1 2 3 4 5 6 7 8 9

But the loop could also follow classic BASIC-style looping rules where the range is fully inclusive [1,10], and the 10 isn't excluded. In that case the loop will execute 10 times, and the output would be:

1 2 3 4 5 6 7 8 9 10

Narue, well I am really confused now, the code is in C++ pseudocode, so with that being said then the loop would execute 9 times?

>so with that being said then the loop would execute 9 times?
That would be my guess, but this is definitely something you should ask your teacher about. Pesudocode is arbitrary; there aren't any hard rules, so for something like this you need to find out what's expected.

IMAO, the word to is inclusive of the two numbers, so it would execute 10 times. But that's just my opinion of that FOR command

>But that's just my opinion of that FOR command
Well, your opinion doesn't define how the loop works. Neither does mine. Only the teacher teaching that pseudocode can tell us what he expects the semantics to be.

This article has been dead for over six months. Start a new discussion instead.