loops done

This commit is contained in:
2015-11-06 12:10:48 +01:00
parent 566d82cd6b
commit f8e09400a2
6 changed files with 152 additions and 84 deletions

View File

@@ -0,0 +1,6 @@
n = 5;
x = 1;
for i = 1:n
x = x * i;
end
fprintf('Faculty of %i is: %i\n', n, x)

View File

@@ -0,0 +1,2 @@
>> facultyLoop
Faculty of 5 is: 120

View File

@@ -0,0 +1,7 @@
n = 5;
counter = 1;
x = 1;
while counter <= n
x = x * counter;
end
fprintf('Faculty of %i is: %i\n', n, x)

View File

@@ -0,0 +1,6 @@
i = 1;
while true % this is always true
disp(x);
x = x * i;
i = i + 1;
end