In Class Exercise on loops and if statements:

These are unrealistic problems, but they help to make sure that you understand the flow of logic and can follow it through to completion.

Problems #1:

start

firstNum = 100

secondNum = 5

thirdNum = 12

the Result = 0

do while secondNum <= thirdNum

if firstNum > 500

firstNum = firstNum * 2

secondNum = secondNum +1

else

firstNum = firstNum + 100

thirdNum = thirdNum -1

end if

end while loop

theResult = firstNum + secondNum + thirdNum

display theResult

end

Problem #2:

start

firstNum = 25

secondNum = 50

thirdNum = 75

fourthNum = 100

ct = 0

workAns = 0

theAns = 0

do while ct < 6

workAns = firstNum + secondNum

if workAns > thirdNum

fourthNum = fourthNum / 2

firstNum = firstNum * 3

secondNum = firstNum - secondNum

thirdNum = thirdNum *2

else

firstNum = firstNum + 10

secondNum = secondNum + 10

thirdNum = thirdNum + 10

end if

ct = ct + 1

end do

theAns = firstNum + secondNum * thirdNum + fourthNum

display theAns

end