Jump to content
Rooster

If Loop in a While loop

Recommended Posts

Hi all,

 

How can I do the following and make ik work?

 

begin
 While (condition) do
   begin
     if (condition) then
       begin
         command
       end;
     command
     command
   end;
end.

 

Because he perfectly checks for the while loop but it completely ignores the if...

 

Any ideas?

Thanks

Link to comment
Share on other sites

IF statement is not a loop, will execute only once if true like:

 

 var i : integer;
begin
i := 1;
while i < 5 do 
  begin
    if i = 3 then 
      begin
        writeln('middle loop! ');  
        //other statements
     end; 
    writeln(i);
    Inc(i);  
    end;
end.

 

this example will write in debug:

1

2

middle loop!

3

4

Edited by Neron
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...