How open parentheses in if expression? - oracle

I have expression. How I can open or rewrite this?
if not ((A or B) and PAR like '%3%') then
--do some code
end if;
Can do this more simple?
Please, give me a link for another expressions as example.

The following should be close to what you're looking for:
IF A = FALSE AND B = FALSE AND REGEXP_LIKE(PAR, '[^3]') THEN
-- code here
END IF;
Share and enjoy.

try the following code
if(A!=true or B!=true)
if(REGEXP_LIKE(name,'[^r]'))
/*code has to be written here*/
end if;
end if;

Related

To Add if else statement into While loop VHDL

I am trying to work on inserting if else to loop but it is still expecting some syntax. I cant figure out why this if/else statement wont compile. I am new to VHDL, please help. This is one of the steps along the way and i am stuck.
variable i : integer := 0;
begin
while i < 10 loop
report "i=" & integer'image(i);
i := i + 1;
if i = 6 then
report "okay good job";
else i = 5 then
report " okay nice work";
else
report " not equal to 5 and 6";
end loop;
wait;
end process;
end architecture;
In VHDL, the keywords are if, elsif and else
if condition_1 then
-- do something
elsif condition_2 then
-- do something else
else
-- do something when all other conditions are false
end if;

syntax error near behavioral

I'm trying to write a code for multiplying two 100x100 matrices in vhdl
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
library work;
use work.mult_100x100_pack.all;
entity multiplier_main_code is
Port ( in_matrix1 : in t_2d_array;
in_matrix2 : in t_2d_array;
out_matrix : inout t_2d_array);
end multiplier_main_code;
architecture Behavioral of multiplier_main_code is
begin
process(in_matrix1, in_matrix2)
begin
for i in 0 to 99 loop
for j in 0 to 99 loop
for k in 0 to 99 loop
out_matrix(i)(j) <= std_logic_vector(signed(out_matrix(i)(j)) + (signed(in_matrix1(i)(k)) * signed(in_matrix2(k)(j))));
end loop;
end loop;
end loop;
end Behavioral;
Its again and again showing an error saying:
expecting type void for "behavioral"
syntax error near "Behavioral"
The code for mult_100X100_pack package is:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
package mult_100x100_pack is
type t_1d_array is array(integer range 0 to 99)of std_logic_vector(7 downto 0);
type t_2d_array is array(integer range 0 to 99)of t_1d_array;
end mult_100x100_pack;
Please, can anybody help me to get around this error?
After fixing your indentation, it should be quite obvious what you are missing:
process(in_matrix1, in_matrix2)
begin
for i in 0 to 99 loop
for j in 0 to 99 loop
for k in 0 to 99 loop
-- Do things
end loop;
end loop;
end loop;
-- Perhaps `end process;` might be appropriate here...
Your process needs an end process; :
end loop;
end process;
end Behavioral;
This illustrates the advantage of taking care to indent code correctly. If all your end fors lined up with their corresponding fors, this would have been obvious.

For loop only going through one iteration

I am trying to create a program that simplifies radicals in TI-BASIC. However, one FOR loop seems to be only completing one iteration while the rest work fine. Here is the code:
Input "Root=",A
Input "Radical=",B
B→Z
ClrList L₃
prgmPRMNTOL1
prgmGETPRIME
The FOR loop in question starts here...
For(Y,1,10)
0→Z
For(X,1,dim(L₂))
If L₁(Y)=L₂(X)
Then
Z+1→Z
End:Disp Z
End
If Z≥A
Then
int(Z/A)*A→C
int(Z/A)→D
For(T,1,D)
L₁(Y)→L₃(1+dim(L₃))
End
For(R,1,C)
ClrList L₄
For(S,1,dim(L₂))
If L₂(S)=L₁(Y) and C>0
Then
–1→L₂(S)
C-1→C
End
End
For(Q,1,dim(L₂))
If L₂(Q)≠–1
Then
L₂(Q)→L₄(1+dim(L₄))
End
End
ClrList L₂
For(Q,1,dim(L₄))
L₄(Q)→L₂(Q)
End
End
End
...and ends here.
1→E
For(M,1,dim(L₃))
E*L₃(M)→E
End
1→F
For(N,1,dim(L₂))
F*L₂(N)→F
End
Disp "OUTSIDE",E,"ROOT",A,"INSIDE",F
The program works perfectly besides the fact that this one loop only runs once. I will post prgmPRMNTOL1 and prgmGETPRIME as well if necessary, though they probably do not have any impact as they modify only L₁ and L₂.
EDIT: Added a indented version.
Input "Root=",A
Input "Radical=",B
B→Z
ClrList L₃
prgmPRMNTOL1
prgmGETPRIME
For(Y,1,10)
0→Z
For(X,1,dim(L₂))
If L₁(Y)=L₂(X)
Then
Z+1→Z
End
End
If Z≥A
Then
int(Z/A)*A→C
int(Z/A)→D
For(T,1,D)
L₁(Y)→L₃(1+dim(L₃))
End
For(R,1,C)
ClrList L₄
For(S,1,dim(L₂))
If L₂(S)=L₁(Y)
Then
–1→L₂(S)
End
End
For(Q,1,dim(L₂))
If L₂(Q)≠–1
Then
L₂(Q)→L₄(1+dim(L₄))
End
End
ClrList L₂
For(Q,1,dim(L₄))
L₄(Q)→L₂(Q)
End
End
End
1→E
For(M,1,dim(L₃))
E*L₃(M)→E
End
1→F
For(N,1,dim(L₂))
F*L₂(N)→F
End
Disp "OUTSIDE",E,"ROOT",A,"INSIDE",F
Close Your Loops
Your issue seems to stem from incorrectly matching your If statements, loops and their End statements.
What's Happening
The behavior of TI-Basic when end of file is reached before all loops and If statements have been closed is to fail silently, terminating the program, rather than alerting the users of an error.
This behavior makes certain odd pieces of code syntactically valid. For instances this snippet would run without error:
For(A,1,10
Disp A
The results being
1
Done
Obviously this is the same as running Disp 1 so, there's no reason to use this an your code. It serves only to make silent and annoying errors appear in code.
The Fix
Assuming the indented version of your code represents how you want your loops to be nested, the code below should fix your problem.
Input "Root=",A
Input "Radical=",B
B→Z
ClrList L₃
prgmPRMNTOL1
prgmGETPRIME
For(Y,1,10)
0→Z
For(X,1,dim(L₂))
If L₁(Y)=L₂(X)
Z+1→Z
End
If Z≥A:Then
int(Z/A)*A→C
int(Z/A)→D
For(T,1,D)
L₁(Y)→L₃(1+dim(L₃))
End
For(R,1,C)
ClrList L₄
For(S,1,dim(L₂))
If L₂(S)=L₁(Y)
–1→L₂(S)
End
End:"Inserted this End
For(Q,1,dim(L₂))
If L₂(Q)≠–1
L₁(Q)→L₄(1+dim(L₄))
End
ClrList L₂
For(Q,1,dim(L₄))
L₄(Q)→L₂(Q)
End
End
End
1→E
For(M,1,dim(L₃))
E*L₃(M)→E
End
1→F
For(N,1,dim(L₂))
F*L₂(N)→F
End
Disp "OUTSIDE",E,"ROOT",A,"INSIDE",F
If that doesn't fix it, the missing End is elsewhere in your code.

What does Ruby's BEGIN do?

What does BEGIN mean in Ruby, and how is it called? For example, given this code:
puts "This is sentence 1."
BEGIN {
puts "This is sentence 2."
}
why is puts "This is sentence 2." executed first?
BEGIN and END set up blocks that are called before anything else gets executed, or after everything else, just before the interpreter quits.
For instance, running this:
END { puts 'END block' }
puts 'foobar'
BEGIN { puts 'BEGIN block' }
Outputs:
BEGIN block
foobar
END block
Normally we'd use a bit more logical order for the BEGIN and END blocks, but that demonstrates what they do.
From the Ruby docs for the BEGIN keyword:
BEGIN: Designates, via code block, code to be executed unconditionally before sequential execution of the program begins. Sometimes used to simulate forward references to methods.
BEGIN and END Blocks
Every Ruby source file can declare blocks of code to be run as the file is being loaded (the BEGIN blocks) and after the program has finished executing (the END blocks).
BEGIN {
begin block code
}
END {
end block code
}
A program may include multiple BEGIN and END blocks. BEGIN blocks are executed in the order they are encountered. END blocks are executed in reverse order.
You can find almost the same post in "Does begin . . . end while denote a 'block'?".
Read more about blocks on tutorialspoint

How to "break" out of a case...while in Ruby

So, I've tried break, next and return. They all give errors, exit of course works, but that completely exits. So, how would one end a case...when "too soon?"
Example:
case x
when y; begin
<code here>
< ** terminate somehow ** > if something
<more code>
end
end
(The above is some form of pseudo-code just to give the general idea of what I'm asking [begin...end was used with the hope that break would work].
And, while I'm at it, is there a more elegant way of passing blocks to case...when?
What's wrong with:
case x
when y;
<code here>
if !something
<more code>
end
end
Note that if !something is the same as unless something
I see a couple of possible solutions.
At the first hand, you can define your block of instructions inside some method:
def test_method
<code here>
return if something
<more code>
end
case x
when y
test_method
end
At the other hand, you can use catch-throw, but I believe it's more uglier and non-ruby way :)
catch :exit do
case x
when y
begin
<code here>
throw :exit if something
<more code>
end
end
end
Ruby has no built-in way to exit the "when" in a "case" statement. You could however get the desired outcome with an answer similar to the technique WarHog gave:
case x
when y
begin
<code here>
break if something
<more code>
end while false
end
or if you prefer:
case x
when y
1.times do
<code here>
break if something
<more code>
end
end

Resources