Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to loop the program.

+6 votes
asked Jan 19 by Meh (180 points)

I'm creating a calculator in PASCAL, I have already created the calculator but I don't want the program to end as soon as I give it one equation to do. What I want is to be able to loop my code over and over again by pressing a key (Y) and end the program when I press another key (N).

3 Answers

+2 votes
answered Jan 19 by Mahery Andrianandraina (180 points)
You can use the loop while
+2 votes
answered Jan 19 by Luciano Herval (180 points)

Sure, here's an example of how you can create a loop in your calculator code so that it continues to run until the user presses a specific key (such as "N"):

Copy code

var continue: char; begin continue := 'Y'; while (continue = 'Y') do begin // your calculator code here writeln('Do you want to continue? (Y/N)'); readln(continue); end; end.

This will create a "while" loop that will continue to execute as long as the "continue" variable is equal to 'Y'. Inside the loop, you can place your existing calculator code, and then ask the user if they want to continue by typing "Y" or "N" using the "readln" command. If the user enters "N", the "continue" variable will be updated and the loop will be terminated, ending the program.

0 votes
answered 2 days ago by haroon73 (140 points)
Use do while loop because it will execute once and then you can ask the user to press Y to continue or N to stop.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...