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

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.

主站蜘蛛池模板: 霍州市| 青铜峡市| 团风县| 滨州市| 昌都县| 柏乡县| 黄山市| 临澧县| 南昌市| 潢川县| 靖安县| 龙口市| 南昌市| 铜川市| 九龙城区| 太谷县| 裕民县| 英山县| 肥西县| 尚志市| 铁岭市| 花莲县| 郯城县| 浙江省| 屯门区| 汕尾市| 泰兴市| 贵定县| 天祝| 兴义市| 泰安市| 疏附县| 扶余县| 辰溪县| 盐源县| 长海县| 商丘市| 区。| 泽州县| 沛县| 云和县|