Recent

Author Topic: pascal:flow control problem  (Read 2027 times)

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
pascal:flow control problem
« on: September 30, 2016, 04:33:01 pm »
users Crt;
var num,count2:integer;
{232,1}begin                     
num:=0;
count2:=0;
        while num=0 do
        begin
                repeat
                writeln('Press Enter to continue/Press ESC to exit');
                ch:=ReadKey;
                until (ch=#27) or (ch=#13);
                case ch of
                #13:begin
                        example1;            {find num}
                        example2;            {find count2}
                        if (num=0) and (count2=0)
                        then begin
                               writeln('keep');
                               readln;
                               end;
                               example3;
                               example4;
                               end;
                #27:exit;
                end;
        end;
end.


i am sory i do not ask my question correctly before.
i want to end the initial  'while' loop after i find num&count2=0 and goto the beginning of looping(not execute example3 & 4)
Also if not(num&count2)=0 ,continue to execute example3 & example4
 
So how can i do?

7vinbaby

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: pascal:flow control problem
« Reply #1 on: September 30, 2016, 04:46:32 pm »
Please, always put you code between [code][/code]-tags.

So
[code=pascal]your pascal-code[/code]

Or select your code and use the #-button above the editor. It wil put these tags around your code.

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: pascal:flow control problem
« Reply #2 on: September 30, 2016, 04:59:31 pm »
@7vinbaby:

You don't have to start a new thread.

Not sure what you want to do. But this is my guess:
Code: Pascal  [Select][+][-]
  1. begin
  2.   num   := 0;
  3.   count2:= 0;
  4.   repeat
  5.  
  6.     ClrScr;
  7.     writeln('Press Enter to continue or ESC to exit.');
  8.     ch := ReadKey;
  9.  
  10.     if ch=#13 then begin
  11.       example1; // find num
  12.       example2; // find count2
  13.       if (num=0) and (count2=0) then begin
  14.         writeln('keep');
  15.         readln;
  16.       end
  17.       else begin
  18.         example3;
  19.         example4;
  20.       end;
  21.     end;
  22.  
  23.   until ch=#27;
  24. end.

Advice for novices:
Don't use non-descriptive names (num, count2, example1, example2, ...), that will only burden your brain to work harder to guess what it is for. Using descriptive names is very helpful especially when your code grows to thousands of lines of code.

edited:
I modify the code a bit to make it better.
« Last Edit: September 30, 2016, 07:31:54 pm by Handoko »

 

TinyPortal © 2005-2018