About Repeat.. until and While.. do - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

About Repeat.. until and While.. do

AfunaAfuna Posts: 2Member
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.

Comments

  • Jeff P.Jeff P. Posts: 196Member
    [code]
    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.
    [/code]
  • AfunaAfuna Posts: 2Member
    The code is a great help.. now I'm beginning to understand the logic involved better :)

    Many thanks for your quick reply!
Sign In or Register to comment.