تقرير if For
تقرير if For
a) Open control function for: By means of this tool we can repeat the
execution of a series of operations within the part allocated to it in the
program and we can repeat a specific operation as needed to reach the
desired output or results.
Where this command is used in a case where the program is free of Errors
and we want to return to the main state of the program or the execution or
the result of the execution of this program is not in the correct form or due to
incomplete input operations
On cases that do not apply to the specific condition placed inside the if
condition statement
With several conditions that are inside several if condition statements that
do not match the conditions that
It deals with special cases and is usually placed inside the switch multi-
condition function
Because it contains more than one case that deals with a conditional
operation that deals with special cases
C) Else if: This is a conditional statement used when there is a specific
operation that does not apply to you or is not completely synonymous with
the previous conditions, which requires writing a new specific condition. All of
these conditions must end with an e-termination statement.
1- If statement:
If logical expression
Statement 1
Else
Statement 2
End
Example 1:
**The a must be specified first to run the program (for example a=2)
If (a ==4)
B=5;
Else
B=8;
End
If (a>b)
Disp (a)
Else
End
Second method:
Nested if
If logical expression1
Statement 1
Statement 2
Else if expression 3
Statement 3
Else
Statement 4
End
End
If the first condition is true, then the first statement will be executed, and if
the first condition is false, then the second condition will be executed, and if
the second condition is false, then the third condition will be executed, and if
the third statement is false, then the statement after else will be executed,
and so on.
Example 3:
If a==1
B=1
Elseif a==2
B=4
Elseif a==3
B=9
Else
B=25
End
End
Example 4: Write a program that checks the value of the variables a and b. If
they are greater than zero, find their product and vice versa. Print that the
value is not greater than zero.
Solution:
Clear; clc
A=input(‘a=’) ; b=input(‘b=’);
C=a * b
Else
End
Statements
End
The loop statement takes the initial value and puts it in the variable, then
executes the statements that follow the loop assignment until reaching the
end statement
It adds the Increment range to the variable to obtain a new value And if the
variable is less than or equal to the final value, if the answer is yes, it goes to
execute from above all the sentences that follow the iteration, but if the
answer is no, it exits the iteration.
Example 1:
For i=1:5
Disp ( I )
End
Example 2: Print the numbers that are named 3 for the number from 3 to 16.
For i= 3:3 :16 disp( I )
End
12
15
Example 3: Print the numbers descending from 22 to 17?
For i=20 : -1 : 17
Disp( I )
End
20
19
18
17
Example 4: Print the numbers that complete the named 3 (from 16 to 3)?
For i= 16 : -1 : 3
If rem(I , 3)==0
Disp( i)
End
End
15
12