User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 423,398 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,557 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 407 | Replies: 1
Reply
Join Date: Nov 2007
Posts: 2
Reputation: sura91 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sura91 sura91 is offline Offline
Newbie Poster

Pascal Help - For Statements ?

  #1  
Nov 18th, 2007
This is the Question:-

3)Implement oon pascal a program to produce the following output:-
*
**
***
****
*****

The number of rows to be printed on the screen should be specified buy the user nad you have to use for loops.


i have done the bit where it just outputs:-
*
**
***
****
*****
but the bit i can do is for the user to specify the number of lines there are?

this is my programming language for the bit i have done:-
  1. Program Question_3;
  2. Uses Wincrt;
  3.  
  4. Var
  5. x : integer;
  6.  
  7. Begin
  8.  
  9. For x:= 1 to 1 do
  10. Begin
  11. write('*')
  12. End;
  13. writeln;
  14.  
  15. For x:= 1 to 2 do
  16. Begin
  17. write('*')
  18. End;
  19. writeln;
  20.  
  21. For x:= 1 to 3 do
  22. Begin
  23. write('*')
  24. End;
  25. writeln;
  26.  
  27. For x:= 1 to 4 do
  28. Begin
  29. write('*')
  30. End;
  31. writeln;
  32.  
  33. For x:= 1 to 5 do
  34. Begin
  35. write('*')
  36. End;
  37. writeln;
  38.  
  39. End.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Pascal Help - For Statements ?

  #2  
Nov 18th, 2007
Any time you find that you are repeating yourself, that is a good thing to turn into a loop.

First, figure out what changes each time and what stays the same. The thing that changes is a variable.
In your examples (done with [inlinecode] so that I can highlight something) they are all the same except for one thing:
For x:= 1 to 1 do
Begin
write('*')
End;
writeln;

The only thing that changes each time is the number of times you go through the for loop. The first time it is 1, the second time it is 2, the third time it is 3, etc. Fortunately, you can use a for loop to count numbers 1, 2, 3, etc. (It is OK to have a loop inside another loop.)

That should be enough to help. Good luck.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 1:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC