# logic - disp'x is less than 0 case'RoundedDownToFive disp'x...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 function [y] = logic(x) % Example of if-then-else fprintf('Example of if-else logic\n') % x = 7.3 % semicolon suppresses screen output if x > 10 disp('x is greater than 10') flag = 'GreaterThanTen' elseif x < 0 disp('x is less than 0') flag ='LessThanZero' else if floor(x) == 5 disp('x rounded downward is equal to five') flag = 'RoundedDownToFive' else disp('x is between 0 and 10') flag = 'BetweenZeroAndTen' end end pause % Example of case fprintf('Example of switch-case logic\n') switch flag case 'GreaterThanTen' % Note: x > 10 will not work disp('x is greater than 10') case 'LessThanZero' % Note: x < 0 will not work

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: disp('x is less than 0') case 'RoundedDownToFive' disp('x rounded downward is equal to five') otherwise disp('x is between 0 and 10') end pause % Example of for loop logic fprintf('Example of for loop logic\n') Sheet1 Page 2 for i = 1:10, if x < i fprintf('x is less than %d\n', i) break end end pause % Example of while loop logic fprintf('Example of while loop logic\n') i = 0 while x > i if x < i+1 % why did I have to say i+1? fprintf('x is less than %d\n', i+1) end i = i+1 end % Pass back x + 1 y = x+1...
View Full Document

## This note was uploaded on 09/05/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

### Page1 / 2

logic - disp'x is less than 0 case'RoundedDownToFive disp'x...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online