关于if then(else)循环的一个简单问题。 [英] A simple question about if then (else) loops.

查看:323
本文介绍了关于if then(else)循环的一个简单问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样做是否有任何好处或缺点:



Are there any benefits or drawbacks in doing this :

If colmod1 = new_colmod1 Then
        Else
            If colmod1 > new_colmod1 Then colmod1 -= 0.001
            If colmod1 < new_colmod1 Then colmod1 += 0.001
        End If





而不是这样做? :





Rather than doing this? :

If colmod1 <> new_colmod1 Then
            If colmod1 > new_colmod1 Then colmod1 -= 0.001
            If colmod1 < new_colmod1 Then colmod1 += 0.001
        End If





它是否编译为相同的代码?我应该避免它吗?




我尝试过:



N / A ..只是为了背景信息和人们的意见。



Does it compile down to the same code? should I avoid it because?


What I have tried:

N/A..Just for background info and what peoples opinions are.

推荐答案

第一个是丑陋的,更难读:应该有优化完成后没有性能差异。
The first one is ugly, and harder to read: there should be no performance difference once optimisation is completed.


它们(视觉)基本相同。您可以选择第一个表格来打乱 Griff
They are (visual) basically the same. You might choose the first form just to upset Griff.


更好的问题。你为什么要测试是否值大于,然后在下一个语句测试中查看值是否小于?



如果值不相等,你只需要另外一个if语句来获得两个结果。

Better question. Why are you testing to see if the value is "greater than" and then in the next statement testing to see if the value is "less than"?

If the value is not equal, you only need one other if statement to get the two outcomes.
If colmod1 <> new_colmod1 Then
    If colmod1 > new_colmod1 Then 
        colmod1 -= 0.001
    Else
        colmod1 += 0.001
    End If
End If


这篇关于关于if then(else)循环的一个简单问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆