Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 difficulties understanding this loop.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lei4848




PostPosted: Fri Jun 09, 2006 10:22 pm   Post subject: difficulties understanding this loop.

for j : 1 .. 3
for k : 1 .. j
put "*" ..
end for
end for

I have difficulties figuring out the output of this program. Please explain how you can solve this program.
Sponsor
Sponsor
Sponsor
sponsor
bluedevils_77




PostPosted: Fri Jun 09, 2006 10:34 pm   Post subject: (No subject)

it just means when j is 1.. then k will only go from 1 to 1.. making 1 star.. when j is 2 the k for will be thru twice.. amking 2 stars.. and when j is 3 the k for will go thru three times.. amking 3 stars.. u could of just done a

for i : 1..6
put "*"
end for
Delos




PostPosted: Fri Jun 09, 2006 10:45 pm   Post subject: (No subject)

bluedevils_77 wrote:
it just means when j is 1.. then k will only go from 1 to 1.. making 1 star.. when j is 2 the k for will be thru twice.. amking 2 stars.. and when j is 3 the k for will go thru three times.. amking 3 stars.. u could of just done a

for i : 1..6
put "*"
end for


Not quite. Notice that the put statement includes a '..', which means that a new line is not created. Hence, you should have the following pattern:
Output:

*
**
***

Otherwise your explanation is quite correct.
TheOneTrueGod




PostPosted: Sat Jun 10, 2006 9:25 am   Post subject: (No subject)

theres no "put "" " so it'll all be on one line, but this question was posted twice, and its obviously a HW / Exam question....
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: