我想把if語句放在my for循環檢查參數中,但我不知道該怎麼做,我想這樣做,所以我不必複製我的代碼,並使它變得龐大,多餘和雜亂。FOR循環語句中的IF語句?
這就是我要做的
for(int i = elevator1CurrentStatus.floorNumber; if(boundary == 9) i<boundary else i>boundary ;i+=i+countDirection){
//Code Here
}
我將如何實現這一點?基本上我想要測試語句說明是否要計數或取決於變量,並根據該變量選擇哪個方向。計數方向是較早實現的,可以是+1或-1。 對(INT I = elevator1CurrentStatus.floorNumber;(如果(邊界== 9)iboundary); I + = I + countDirection)
for(int i = elevator1CurrentStatus.floorNumber; (if(boundary == 9) i<boundary else i>boundary) ;i+=i+countDirection)
你能解釋一下你的IF條款?你在做什麼,如果(邊界== 9)我<邊界其他我>邊界' – Ankit