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.

+12 votes
asked Jan 19, 2023 by Meh (220 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).

4 Answers

+3 votes
answered Jan 19, 2023 by Mahery Andrianandraina (200 points)
You can use the loop while
+2 votes
answered Jan 19, 2023 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.

+1 vote
answered Jan 25, 2023 by haroon73 (160 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.
–1 vote
answered Jan 30, 2023 by Sachin sah (160 points)
USE WHILE LOOP WITH #INCLUDE<STDLIB.H> AS A HEADER AND...MAKE THEIR CONDITION OF EXIT AND U CAN HAVE A PERFECT ANS
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.
...