Computer Science Canada

difficulties understanding this loop.

Author:  lei4848 [ 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.

Author:  bluedevils_77 [ Fri Jun 09, 2006 10:34 pm ]
Post 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

Author:  Delos [ Fri Jun 09, 2006 10:45 pm ]
Post 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.

Author:  TheOneTrueGod [ Sat Jun 10, 2006 9:25 am ]
Post 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....


: