Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2012
    Posts
    1

    Unanswered: Help in understanding the PLSQL prime number program logic.

    Hi ALL,

    i am new to PLSQL , can someone help in understanding the PLSQL prime number program ...which i got from tutorials point .com
    Here goes the pogram:

    DECLARE
    i number(3);
    j number(3);
    BEGIN
    i := 2;
    LOOP
    j:= 2;
    LOOP
    exit WHEN ((mod(i, j) = 0) or (j = i)); j := j +1;
    END LOOP;
    IF (j = i ) THEN
    dbms_output.put_line(i || ' is prime');
    END IF;
    i := i + 1;
    exit WHEN i = 50;
    END LOOP;
    END;
    /


    I am not getting the logic behind it can some body explain it anfd oblige plz.


    Regards,

    Ceager chethan

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Your best option (in my opinion) is to take a pencil and piece of a paper and write everything that code does, step by step (i.e. line by line). I sincerely hope that you won't have to loop until I becomes 50.

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    no even number greater than 2 can be a prime number.

    OraFAQ Forum: SQL & PL/SQL PL SQL prime number program explanation.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •