for loop question

Reply

Join Date: Nov 2007
Posts: 3
Reputation: m16jim is an unknown quantity at this point 
Solved Threads: 0
m16jim m16jim is offline Offline
Newbie Poster

for loop question

 
0
  #1
Nov 8th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,026
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 125
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: for loop question

 
0
  #2
Nov 8th, 2007
Do you know what a loop is? Read this page:

http://en.wikipedia.org/wiki/For_loop
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3
Reputation: m16jim is an unknown quantity at this point 
Solved Threads: 0
m16jim m16jim is offline Offline
Newbie Poster

Re: for loop question

 
0
  #3
Nov 8th, 2007
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?
Last edited by m16jim; Nov 8th, 2007 at 2:04 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: for loop question

 
0
  #4
Nov 8th, 2007
yes
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: for loop question

 
0
  #5
Nov 8th, 2007
>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. 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. 1 2 3 4 5 6 7 8 9 10
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3
Reputation: m16jim is an unknown quantity at this point 
Solved Threads: 0
m16jim m16jim is offline Offline
Newbie Poster

Re: for loop question

 
0
  #6
Nov 8th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: for loop question

 
0
  #7
Nov 8th, 2007
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: for loop question

 
0
  #8
Nov 8th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: for loop question

 
0
  #9
Nov 9th, 2007
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC