| | |
for loop question
![]() |
•
•
Join Date: Nov 2007
Posts: 3
Reputation:
Solved Threads: 0
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.
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 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:
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:
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:
C++ Syntax (Toggle Plain Text)
1 2 3 4 5 6 7 8 9
C++ Syntax (Toggle Plain Text)
1 2 3 4 5 6 7 8 9 10
I'm here to prove you wrong.
>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.
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.
I'm here to prove you wrong.
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
Last edited by WaltP; Nov 8th, 2007 at 8:51 pm.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- C++ For Loop User Response (C++)
- Simple script loop question (Shell Scripting)
- C++ Loop Question Here (C++)
- C++ For Loop Question (C++)
- while loop question (Python)
- how to use loop in this question (C++)
- need help w/for loop (C++)
- I need to re-write this code using a 'while' loop. (Java)
Other Threads in the C++ Forum
- Previous Thread: Help!
- Next Thread: Converting char into int
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets







