Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Why doesn't this work? I'm getting unexpected keyword_end.
while(!k && DATA[q])
if DATA[q] == 'aa' && DATA[p] == 'aa'
pl = DATA[r]
for i in 0..pl
PACK[i] = DATA[i+4]
end
k+=1 #end while
else
q++
p++
r++
end
end
You are getting error because ++ does not work in Ruby.
Ruby has no pre/post increment/decrement operator. For instance, x++
or x-- will fail to parse. More importantly, ++x or --x will do
nothing! In fact, they behave as multiple unary prefix operators: -x
== ---x == -----x == ...... To increment a number, simply write x += 1.
source (which indeed are the words of Ruby's author himself.)
You should replace them as follows:
q+=1
p+=1
r+=1
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
if true || 0/0 == 0 {
print()
}
If the first parameter is true, then the 0/0 wouldn't be evaluated.
Why does this return a DIVIDE BY ZERO error?
The divide by zero here is a compiler error, not a runtime error. Shortcutting only applies at runtime. If you change it to 0/x where x is set to zero, you won't get the error:
var x = 0
if true || 0/x == 0 {
print()
}
https://play.golang.org/p/7E9MMqUbnQm
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Hi sorry for a basic question on VBScript but after scouring the internet. In a If statement I am trying to assign values to 2 fields but when I run this code which is part of an application it does not error neither does it work so I suspect I am doing wrong. Can anyone point me in the right direction as I am trying to assign values to CustomerInformation.CodeObject.Customer and. CustomerInformation.CodeObject.Carrier
Function CustomerInformation_OnLoad()
if (SystemVariables.CodeObject.Company = "D" or SystemVariables.CodeObject.Company = "T") and DispatchNoteDetails.CodeObject.Area = "UK" then
if CustomerInformation.CodeObject.Customer = "AAE02" then
CustomerInformation.CodeObject.Carrier = "Customer collects" and CustomerInformation.CodeObject.CarrierURN = "AA Driver"
end if
end if
End Function
Hi thanks all for the tips.
The code worked when changing to the following:
Function CustomerInformation_OnLoad()
if (SystemVariables.CodeObject.Company = "D" or SystemVariables.CodeObject.Company = "T")then
if CustomerInformation.CodeObject.Customer = "AAE02" then
CustomerInformation.CodeObject.Carrier = "Customer collects"
CustomerInformation.CodeObject.CarrierURN = "AA Driver"
end if
end if
End Function
Thanks again for the tips.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Am newbie in programming, just curious, what is the difference between
if(a == 1)
{
//condition
}
if(b == 1)
{
//condition
}
and
if(a == 1 || b == 2)
{
//condition
}
I don't have any questions regarding this, all I want is clarification. Don't over think guys, I know you're all pro's. Take note on the "just curious", cause am noob.
The first statement compares the variable 'a' to '1', and if the variable 'a' is equal to '1', then you will execute the block of code enclosed in brackets. Likewise, the first statement also compares the variable 'b' to '1' and if equal will execute a block of code.
The second expression evaluates two conditions, 'a' being equal to 1, and 'b' being equal to '2'. If either expression is true, then the block of code enclosed in brackets will execute. The double pipe symbol '||' is synonymous with 'or'.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to make n random numbers from -0.5 from to 0.5
and I made a function like this
def create_noise(n)
end
I found an implementation of this but i don't think this works
randoms = Set.new
loop
randoms << rand(max)
return randoms.to_a if randoms.size >= n
You would just do
def create_noise(n)
n.times.collect { rand(-0.5..0.5) }
end
that will spit back an array like this:
[-0.034680737617880486, 0.34802029078157803, 0.1346483808607455, 0.12155616615186282, -0.41043213731234474]
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a method that will return a number between 1 - 100
depending on whether the response (x) is between
100 - 90 i would like one response, 89 - 85 another 84 - 72 another ... etc
I use
if x > 90
response a
elsif x > 85
response b
elsif etc...
but this seems a little messy, is there a better way of refactoring this?
Many thanks.
Take advantage of Range#=== and use a case statement:
case x
when 72..84
# Do something
when 85..89
# Do something
when 90..100
# Do something
else
# Do something when no matches
end
You could try a table (a Hash) where the keys are ranges and the values ar the numbers you want to return :
T = {
(90..100) => 1,
(85..89) => 2,
# and so on
}
(r,v) = T.find {|r,v| r.member? x}
if v then
return v
else
# x wasn't in any of the defined ranges
end