# Algorithm-OUTPUT OF THE

Locked

### Algorithm-OUTPUT OF THE

WHAT WILL BE THE OUTPUT USING 1,3,2,2,4,5,6,2,0?

value=0
new value=0
input value
input next_value
WHILE new_value is not equal to zero DO
IF new_value is greater than value
THEN value is equal to new_value
ENDIF
input next_value
ENDWHILE
output value

### 0: WHILE is never invoked because new_value = 0

Stop wasting everybody's time.

### Wild stab in the dark based on an iffy guess

you should get 1 ( new_value <> 0 is false so value will be the first item in the list

Presumably you was after six

value = 0
Do
input next_value
if (next_value > value)
then value = next_value
end if
While (next_value != 0)
output value

You always want to read one value from the list so a Do while loop is the chap you want.

saves all sorts of arsing about trying to make it execute at least once.

There's an old and proven technique called dry running

from my algorithm

1,3,2,2,4,5,6,2,0
would give
Iteration value next_value (!=0)
0 0 1
1 1 3 No
2 3 2 No
3 3 2 No
4 3 4 No
5 4 5 No
6 5 6 No
7 6 2 No
8 6 0 Yes

### No, Tony Hopkinson, "new_value" <> "next_value"

WHILE loop is never invoked, 0 = 0

0 + 0 = 0

0 * 0 = 0

etc.

### 0: WHILE is never invoked because new_value = 0

Stop wasting everybody's time.

### Wild stab in the dark based on an iffy guess

you should get 1 ( new_value <> 0 is false so value will be the first item in the list

Presumably you was after six

value = 0
Do
input next_value
if (next_value > value)
then value = next_value
end if
While (next_value != 0)
output value

You always want to read one value from the list so a Do while loop is the chap you want.

saves all sorts of arsing about trying to make it execute at least once.

There's an old and proven technique called dry running

from my algorithm

1,3,2,2,4,5,6,2,0
would give
Iteration value next_value (!=0)
0 0 1
1 1 3 No
2 3 2 No
3 3 2 No
4 3 4 No
5 4 5 No
6 5 6 No
7 6 2 No
8 6 0 Yes