

To do it, we assigned a counter ‘y’ which has an initial value of 1. In this example about the use of the ‘while’ command, we want to find the first element of vector ‘a’ which is bigger than 60. Take a look at the example below about ‘while’ command in Matlab®. Then you can see the last value of ‘y’ at the command window in the example above in Matlab®. In each loop, we increase the value of ‘x’ for 1. To do this, we used the ‘while’ code that the code inside the loop will work while the condition x>y is true. So, we need to stop the working of code when the values of ‘x’ and ‘y’ are equal. In the ‘while’ loop, we want to increase the value of ‘y’ up to the value of ‘x’. There are starting values of ‘x’ and ‘y’ variables, which are 5 and 1 respectively. Here you can see a very basic example of the use of the ‘while’ loop in Matlab®. If you are interested to learn Matlab® at an engineering level, click on the given link or the ‘Shop Now’ button to check the recommended book by Mechanical Base, from Amazon! How To Use ‘while’ Loop In Matlab®? > x = 5 The use of the while command in Matlab® to code loops is very easy. Along with the for-end loop, while loop is also a loop programming command in Matlab®. Like in other programming languages, you can also code loops in Matlab®.
