- Learning Quantitative Finance with R
- Dr. Param Jeet Prashant Vats
- 199字
- 2021-07-09 19:06:51
Loop control statements
There are control statements that can change the normal sequence of execution. break
and next
are loop control statements, and we will briefly discuss these control statements here.
break
break
terminates the loop and gives control to the next following statement of the loop; for example:
>Vec <- c("Hello") >counter <- 5 >repeat { >+ print(Vec) >+ counter <- counter + 1 >+ if(counter > 8) { >+ break >+ } >+}
As a result of the break
statement, when the preceding statement gets executed, it prints Hello
four times and then leaves the loop. repeat
is another loop construct that keeps executing unless a stop condition is specified.
next
next
does not terminate the loop, but skips the current iteration of the flow and goes to the next iteration. See the following example:
>Vec <- c(2,3,4,5,6) >for ( i in Vec) { >+ if (i == 4) { >+ next >+ } >+ print(i) >+}
In the preceding example, when the iteration goes to the third element of vector Vec
, then the control skips the current iteration and goes back to the next iteration. So, when the preceding statement gets executed, it prints vector elements 2
, 3
, 5
, and 6
, and skips 4
.
- Hands-On Neural Networks with Keras
- 樂(lè)高創(chuàng)意機(jī)器人教程(中級(jí) 下冊(cè) 10~16歲) (青少年iCAN+創(chuàng)新創(chuàng)意實(shí)踐指導(dǎo)叢書)
- 分布式多媒體計(jì)算機(jī)系統(tǒng)
- Arduino &樂(lè)高創(chuàng)意機(jī)器人制作教程
- 電腦主板現(xiàn)場(chǎng)維修實(shí)錄
- RedHat Linux用戶基礎(chǔ)
- Applied Data Visualization with R and ggplot2
- C++程序設(shè)計(jì)基礎(chǔ)(上)
- 精通LabVIEW程序設(shè)計(jì)
- Building Google Cloud Platform Solutions
- 實(shí)戰(zhàn)Windows Azure
- Kubernetes on AWS
- 網(wǎng)頁(yè)設(shè)計(jì)與制作
- 微機(jī)組裝與維護(hù)教程
- Flash CS3動(dòng)畫制作