Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
About Repeat.. until and While.. do Posted by Afuna on 1 Mar 2002 at 4:46 AM
Hi, am new here.. anyway, I was hoping somebody could give me information about programming using repeat and while..

The problem is :

using while .. do

5
5 4
5 4 3
5 4 3 2
5 4 3 2 1


and using repeat until
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1


I've been puzzling over this for a while and all my efforts have given me an output of:
5
4
3
2
1

for the 'while' and similar output for the 'repeat'

Is the process similar to the 'for'?
I've been able to do the required output using FOR command, but I cannot seem to apply it to REPEAT and WHILE.

Your help would be greatly appreciated.

Report
Re: About Repeat.. until and While.. do Posted by Jeff P. on 2 Mar 2002 at 6:09 AM
program looptest;

var
  I, N:integer;
  
begin
  WriteLn('using while .. do');
  N:=5;
  while ( N >= 1 ) do begin
    I:=5;
    while (I >= N ) do begin
      write(I ,#32);
      dec(I)
    end;
    writeln;
    dec(N);
  end;
  WriteLn( 'using repeat .. until');
  N:=5;
  repeat
    I:=0;
    repeat
      inc(I);
      write(I, #32);
    until ( I >= N );
    writeln;
    dec(N);
  until ( N < 1 );
end.

Report
Thank you very much ^^ Posted by Afuna on 2 Mar 2002 at 6:23 AM
The code is a great help.. now I'm beginning to understand the logic involved better :)

Many thanks for your quick reply!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.