convert for loop to while

1 view (last 30 days)
Mohammed Bokhow
Mohammed Bokhow on 7 Apr 2020
Edited: darova on 7 Apr 2020
how can i convert this
n=5;fact = 1 ;
for i = 1:n
fact =fact * i;
end;
disp(fact)
into while loop
with my best regards

Accepted Answer

KSSV
KSSV on 7 Apr 2020
Edited: darova on 7 Apr 2020
i = 1 ;
f = 1 ;
n = 3 ;
while i<=n
f=f*i;
i = i+1 ;
end
  6 Comments
KSSV
KSSV on 7 Apr 2020
I gave you the answer.......you need to change the variables accoridng to yours thats it...
Mohammed Bokhow
Mohammed Bokhow on 7 Apr 2020
ok how can i change them i'm bignner at using matlab

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!