There is no loop that is in the matub, but this loop is there to execute a specific function in the program in other programming languages such as C, C + +. The two types of loops are used as do operations, rather than using the Do-loop loop in the matub. A programmer can use "for loop" if he is sure how many times he needs to do a particular job. However, if the programmer is unsure of the number of tasks he has to perform, the programmer can use the "loop" in the program. In the loop statement, a condition can be written and the statements of a particular code may be repeated and the variable will be reduced/increased as per the requirement.
However, if the syntax used to write the loop program is "while", at the end of the program, you should write the ' end ' code to stop the functioning of the loop. This post will help you understand how to do while in the Matab program to increase/decrease the variable in the code.
How to use while loop Mattab?
To write a loop statement for a while in the matub, the programmer should always consider the following points:
The start-up situation is used to limit the execution time of the loop.
The second statement is used to determine the output of the program.
The third factor used to increase the variable of given loop is. If a programmer does not write the increment line, then the loop runs until infinite time.
The syntax of doo while in Matab
As we know, a normal loop is when in a matub, which is used to predict the program at least once. Hence, the simplest method to implement the program is to start the program with a brief loop that has a true statement and to observe the re-Val of the given situation till the end of the loop.
Syntax
Window = true;
Condition% will run a program
Condition =.. .% of Test status write here.
The end
OR
Situation
Statement No 1
.
.
Statement number n
Syntax for growth/reduction loop variable
The example to be done when Matab is programmed
Example 1:
In the given example, let the variable x be. The starting value can be assigned to variable x 4. However, after applying a certain condition with the loop statement (x < = 9), loop executes a value of 4, 5, 6, 7, 8, 9. Statement only shows X's value; So, it can show the output as 4, 5, 6, 7, 8, 9.
Program
X = 4
(X < = 9)
DISP (x)
X = x + 1;
The end
Output
X = 4
4
5
6
7
8
9
Example 2:
This example has a square function, meaning that this program finds a square of values up to 6. There is a "var" in the program, which is used to indicate the variable name. The value of Var is 2, and it executes value from 2 to 6.
Program
Var = 2
However (var < = 6)
Square = var * var;
Disp (Chada)
Var = var + 1;
The end
Output
Ver = 2
4
9
16
25
36
Example 3:
There are two types of activities in this example: one is to describe odd numbers and the other is used for equal numbers. To check whether the number is odd number or even number, we have used a variety of traps.
Program
Var = 1
Disp (' numbers odd ')
However (var < = 8)
Disp (VAR)
Var = var + 2;
The end
Var = 0
Disp (' numbers equals ')
However (var < = 8)
Disp (VAR)
Var = var + 2;
The end
Output
Var = 1
Numbers are odd
1
3
5
7
Var = 0
The numbers are equal
2
4
6
8
Example 4:
In Example 3, we have enabled numeric value from source, but at this point, we use loop for a while to change the range of numeric values. In this example, we have started the number from 21 to 45. We have two different variables, where it is used to start "Var" and "End" is used for the end of the program.
Program
% Odd numbers between 21 to 45
Var = 21
Disp (' numbers odd ')
However (var < = endat)
Disp (VAR)
Var = var + 2;
The end
Var = 20
Endat = 45
Disp (' numbers equals ')
However (var < = 45)
Disp (VAR)
Var = var + 2;
The end
Output
Var = 21
Numbers are odd
21
23
25
27
29
31
33
35
37
39
41
43
45
Var = 20
Endat = 45
The numbers are equal
20
22
24
26
28
30
32
34
36
38
40
42
44
Example 5:
With the help of loop for a while, we can create a number of apps and ranges. In the following example, we have created a number series, according to the previous example result.
Program
% Extra for last numbers
Var = 0
Endat = 5
X = 0
Disp (' range of numbers ')
However (var < = endat)
% Disp (VAR);
X = x + var
Var = var + 1;
The end
Output
Var = 0
Endat = 5
X = 0
Series of Numbers
X = 0
X = 1
X = 3
X = 6
X = 10
X = 15
The end
In this post, two main traps are used when the Matab coding program is in and it is "however" and "for" loop. The "If" loop is used in a program that does not know about repetitive advertisements to the programmer. "For" is used when you are sure of a repetition of a programmer statement. The above mentioned examples have shown in many ways the use of loop for a while. It improves the program efficiency and also reduces the complexity of the program. You are faced with a problem related to the Mattab assignment; Then, you can get our expert help for matub assignment help. We have a number of experts who can provide you high-quality data at the time of slot. We are also renowned for our best services available at affordable prices. So, take our services and relax from your matub online Help.