Question

Can somebody please help me understand the following piece of pseudo code:

int x=2, y=3, z=4

DO 
  x *= 3
  If (x>50) Then
     y --
  Else
    z ++
  End If
 WHILE(y>0)

In particular, I'm not sure what 'z++' , '*=' and 'y--' means. Also, how would I create a complete a trace table for this (columns 'x' , 'y', and 'z').

Thanks

Was it helpful?

Solution

"z++" is refering to the suffix version of the incrementation of the variable z. Meaning z is now z+1. " *= " is the short form of a=a*b (a*=b).

DO 
  x *= 3
  If (x>50) Then
     y --
  Else
    z ++
  End If
 WHILE(y>0)

While y is greater then zero, do : multiply x by 3. If x is greater 50 then lower y by 1. If x is 50 or less increase z by 1.

So for the triplet (x,y,z) it would give this steps: (2,3,4) , (6,3,5), (18,3,6), (54,2,6), (162,1,6), (468,0,6).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top