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

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.

主站蜘蛛池模板: 孟州市| 元江| 岢岚县| 清丰县| 竹北市| 景德镇市| 陇川县| 自治县| 黔南| 宜兰县| 施甸县| 土默特右旗| 日土县| 百色市| 左贡县| 甘谷县| 红原县| 金湖县| 子长县| 惠东县| 福建省| 新丰县| 陆河县| 利辛县| 通州区| 高安市| 阳信县| 德清县| 丰镇市| 嘉鱼县| 青州市| 顺平县| 竹北市| 突泉县| 滕州市| 东乡| 蒙山县| 贵港市| 闻喜县| 莱阳市| 镶黄旗|