Looping and Conditional-Control Flow : Iteration conditioned

Take a look also at the previous article: Looping and Conditional-Control Flow : Repetition / Iteration / Looping 

Iteration conditioned (While. .. end).
This syntax is used to perform the process without a known repetition of repetition. Iterations of this type of repetition only stop when it reaches certain conditions. Eg calculate the amount of glass needed to accommodate the contents of the tub. The way the writing is as

while conditions

For clarity, the following are examples of its use in the program:
1. In the command window, type:
>> Edit

2. Press Enter, then when MATLAB editor appear, type or copy the program below:
clear all;

disp ('--------------------------');
disp ( 'My 5th Training Program');
disp ('--------------------------');

vbasin = input ( 'volume of the tub (ltr) =');
vglass = input ( 'glass volume (ltr) =');

nglass = 0;while vbasin> 0nglass = nglass +1;
vbasin = vbasin - vglass;

disp ([ 'glasses required =' num2str (nglass)]);

3. When finished typing the above programs, you save in the directory c: / mytraining, with the name training05.m

4. Ensure your file storage directory is contained in the directory search list MATLAB. Learn it in the MATLAB directory management  here. Then type the file name without the extension training04:
>> training05

5. Press Enter, then the program will run and produce as follows:
My 5th Training Program
bath volume (ltr) = 2
glass volume (ltr) = 0.2
glass required = 11

6. Done


Post a Comment