SUNY Geneseo Department of Mathematics
Wednesday, October 29
Math 230 01
Fall 2014
Prof. Doug Baldwin
... initialization ...
while C
% C (and body) have to be evaluable on 1st iter.
% Body has to eventually make C false
...
end
>> while x > 1
x = x/10;
% increment count
end
{Undefined function or variable 'x'.
}
% Oops, needed to initialize x (and the counter)
>> x = 7829;
>> c = 0;
>> while x > 1
x = x/10;
c = c + 1;
end
>> x = 7829;
>> c = 0;
>> while x ~= 1
x = x / 10;
c = c + 1;
end
% Program runs and runs and runs because x is never exactly 1. Interrupt with control-C
>> c
c =
1.7941e+10
>> n = 8935;
>> d = input( 'Guess a divisor of n ' );
Guess a divisor of n 0
>> while d == 0 && n/d ~= int32( n/d )
d = input( 'Guess a divisor of n ' );
end
Guess a divisor of n 3
>> n/d
ans =
2.9783e+03