cscgal
The Queen of DaniWeb
19,423 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>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
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
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
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401