IF Statements flowcharts and pseudocode Please open the

  • Slides: 20
Download presentation
IF Statements flowcharts and pseudocode Please open the speaker notes - they contain additional

IF Statements flowcharts and pseudocode Please open the speaker notes - they contain additional information!

Simple IF - processing on Y only N IF AMT > 5000 Y AMT

Simple IF - processing on Y only N IF AMT > 5000 Y AMT x 10 = ANS if amt > 5000 ans = amt * 10 end if

Simple IF - processing on Y or N N ANS = AMT x 5

Simple IF - processing on Y or N N ANS = AMT x 5 if amt > 5000 ans = amt * 10 else ans = amt * 5 end if IF AMT > 5000 Y ANS= AMT x 10 In this example, if the AMT is greater than 5000 then we want to multiply AMT by 10 and store the answer in ANS. If the AMT is not greater than 5000 then we want to multiply AMT by 5 and store the answer in ANS.

AND relationship N Y IF INVCD = “A” N IF AMT > 5000 Y

AND relationship N Y IF INVCD = “A” N IF AMT > 5000 Y MOVE “OKAY” TO MSG if invcd = “A” if amt > 5000 move “OKAY to msg end if Both statements must be true for the msg to receive the word OKAY. If either statement is false, no processing is done.

AND relationship N IF INVCD = “A” N Y IF AMT > 5000 Y

AND relationship N IF INVCD = “A” N Y IF AMT > 5000 Y MOVE “OKAY” TO MSG if invcd = “A” if amt > 5000 move “OKAY to msg end if if invcd = “A” and amt > 5000 move “OKAY” t 0 msg end if

AND relationship N Y IF INVCD = “A” MOVE “PROBLEM” TO MSG N IF

AND relationship N Y IF INVCD = “A” MOVE “PROBLEM” TO MSG N IF AMT > 5000 MOVE “PROBLEM” TO MSG if invcd = “A” if amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if Y MOVE “OKAY” TO MSG if invcd = “A” and amt > 5000 move “OKAY” to msg else move “PROBLEM” to msg end if

AND relationship N IF INVCD = “A” N MOVE “PROBLEM” TO MSG if invcd

AND relationship N IF INVCD = “A” N MOVE “PROBLEM” TO MSG if invcd = “A” if amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if Y IF AMT > 5000 Y MOVE “OKAY” TO MSG

AND relationship N IF INVCD = “A” MOVE “BAD CODE” TO MSG N MOVE

AND relationship N IF INVCD = “A” MOVE “BAD CODE” TO MSG N MOVE “PROBLEM” TO MSG if invcd = “A” if amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if else move “BAD CODE” to msg end if Y IF AMT > 5000 Y MOVE “OKAY” TO MSG

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 Y MOVE “OKAY” TO MSG One or the other of the if questions must be true for OKAY to be moved to msg. if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg end if

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 Y MOVE “OKAY” TO MSG if invcd = “A” or amt > 5000 move “OKAY to msg end if if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg end if

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 MOVE “PROBLEM” TO MSG if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg else move “PROBLEM” to msg end if Y MOVE “OKAY” TO MSG

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF

OR relationship N IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 MOVE “PROBLEM” TO MSG if invcd = “A” or amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if Y MOVE “OKAY” TO MSG if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg else move “PROBLEM” to msg end if

OR relationship N N IF AMT > 5000 MOVE “PROBLEM” TO MSG if invcd

OR relationship N N IF AMT > 5000 MOVE “PROBLEM” TO MSG if invcd = “A” move “CODE - OKAY” to msg else if amt > 5000 move “AMT - OKAY” to msg else move “PROBLEM” to msg end if IF INVCD = “A” Y MOVE “AMT - OKAY” TO MSG Y MOVE “CODE - OKAY” TO MSG

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A”

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A” N N IF AMTSND > 200 IF AMTFST > 500 Y MOVE “OKAY” TO MSG if invcd = “A” if amtfst > 500 move “OKAY” to msg else if amtsnd > 200 move “OKAY” to msg end if Y MOVE “OKAY” TO MSG

cond 1 AND (cond 2 OR cond 3) N if invcd = “A” and

cond 1 AND (cond 2 OR cond 3) N if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if Y IF INVCD = “A” N IF AMTFST > 500 Note the use of parenthesis here. In boolean logic AND gets resolved before OR. That means if we did not have the parenthesis, it would treat this like invcd = A and amtfst > 500 or just amtsnd > 200. Y Continue below N IF AMTSND > 200 Y MOVE “OKAY” TO MSG We want the logic to be invcd = A and either amtfst > 500 or amtsnd >200. To do this, we need to change the order of operation so that the two things in the or relationship are grouped together. We do this by using parenthesis.

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A”

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A” N N IF AMTSND > 200 IF AMTFST > 500 Y MOVE “OKAY” TO MSG if invcd = “A” if amtfst > 500 or amtsnd > 200 move “OKAY” to msg end if Y MOVE “OKAY” TO MSG

if invcd = “A” and amtfst >500 or amtsnd > 200 move “OKAY” to

if invcd = “A” and amtfst >500 or amtsnd > 200 move “OKAY” to msg end if cond 1 AND cond 2 OR cond 3 N N IF AMTSND > 200 Y IF INVCD = “A” Y N IF AMTFST > 500 Y MOVE “OKAY” TO MSG N IF AMTSND > 200 Y MOVE “OKAY” TO MSG

cond 3 OR cond 1 AND cond 2 N N Y IF AMTSND >

cond 3 OR cond 1 AND cond 2 N N Y IF AMTSND > 200 Y IF INVCD = “A” N IF AMTFST > 500 MOVE “OKAY” TO MSG Y MOVE “OKAY” TO MSG if amtsnd > 200 or invcd = “A” and amtfst > 500 move “OKAY” to msg end if

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A”

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A” N N MOVE “PROBLEM” TO MSG IF AMTSND > 200 IF AMTFST > 500 Y MOVE “>200 -OKAY” TO MSG if invcd = “A” if amtfst > 500 move “>500 - OKAY” to msg else if amtsnd > 200 move “>200 -OKAY” to msg else move “PROBLEM” to msg end if Y MOVE “ >500 - OKAY” TO MSG

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A”

cond 1 AND (cond 2 OR cond 3) N Y IF INVCD = “A” MOVE “CODE PROBLEM” TO MSG N MOVE “PROBLEM” TO MSG N IF AMTSND > 200 IF AMTFST > 500 Y MOVE “>200 -OKAY” TO MSG Y if invcd = “A” if amtfst > 500 move “>500 - OKAY” to msg else if amtsnd > 200 move “>200 -OKAY” to msg else move “PROBLEM” to msg end if else move “CODE PROBLEM” to msg end if MOVE “ >500 - OKAY” TO MSG