官术网_书友最值得收藏!

Time for action – Using if/else

Let's write some code to see if/else in action for ourselves.

  1. Take the following code:
    var int Int1, Int2;
    
    function PostBeginPlay()
    {
        if(Int1 > Int2)
            'log("Int1 is greater than Int2");
        else if(Int1 == Int2)
            'log("Int1 is equal to Int2");
        else
            'log("Int1 is less than Int2");
    }
    
    defaultproperties
    {
        Int1=5
        Int2=2
    }
  2. What would we expect the result to be? Let's look at the log for the answer:
    [0007.72] ScriptLog: Int1 is greater than Int2

What just happened?

We can see that the if statement is executed and not the else if or else statements. Notice that in this example we didn't use the curly brackets in our statements. If there is only one line after the if, else if, or else statements brackets aren't necessary. However, if there are two or more lines, we would need to use brackets.

For

For is a different kind of control statement called an iterator. It will execute the code we write a specific number of times until a condition is met. Let's take a closer look at it.

主站蜘蛛池模板: 淅川县| 铁岭市| 平乐县| 微博| 万山特区| 临洮县| 苍溪县| 老河口市| 嘉定区| 白银市| 和硕县| 罗定市| 朝阳县| 新安县| 乌拉特中旗| 长阳| 平南县| 遵化市| 柳州市| 汾西县| 睢宁县| 宝兴县| 隆德县| 德惠市| 泰顺县| 县级市| 乌鲁木齐县| 旬邑县| 乌鲁木齐县| 嘉善县| 赣州市| 崇义县| 双鸭山市| 磴口县| 嘉祥县| 广德县| 德州市| 宿迁市| 商洛市| 大理市| 德兴市|