mardi 10 octobre 2017

While Loop and If/Else in PL/SQL

I am trying to write a procedure that will produce the following output

exec WinOrLose(4)

Welcome to the Win or Lose Game. Your number is 4. 

You win.
You lose.
You win.
You lose.

==> You lose!

So far I have this:

CREATE or REPLACE Procedure WinOrLose (
  p_choice number ) AS

  v_answer number;

DECLARE
  v_answer := p_choice

BEGIN
  dbms_output.put_line ('Welcome to the Win or Lose Game. Your number is ' || 
  v_answer);

  FOR v_answer in 1..10 
    IF MOD(v_answer, 2) = 0 THEN -- v_answer is even
          dbms_output.put_line (You lose)

END;
/

I'm unsure of where to go from there. My thought process (psuedocode) is this:

SET v_answer := 1
   While Loop (outside)
     MOD(v_answer,2) = 0 then dbms.output (YOU LOSE)
   ELSE
     dbms.output (YOU WIN)
   end if;
     v_answer := p_choice

Aucun commentaire:

Enregistrer un commentaire