Q:

Write a program in PL/SQL to check whether a number is prime or not using goto statement with for loop

0

Write a program in PL/SQL to check whether a number is prime or not using goto statement with for loop.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PL/SQL Code:

DECLARE
  msg  VARCHAR2(30);
  n  PLS_INTEGER := 83;
BEGIN
  FOR i in 2..ROUND(SQRT(n)) LOOP
    IF n MOD i = 0 THEN
      msg := ' is not a prime number';
      GOTO when_prime;
    END IF;
  END LOOP;

  msg := ' is a prime number';
 
  <>
  DBMS_OUTPUT.PUT_LINE(TO_CHAR(n) || msg);
END;
/

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now