An Interest In:
Web News this Week
- March 22, 2024
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
March 29, 2022 03:40 pm GMT
Original Link: https://dev.to/ilosrim/lasson-04-loops-and-errors-4f5p
Lasson 04 | Loops and errors
Types of Loops
Loops can be written as while
loops, do-while
loops, and for
loops.
while Loops
while
loops iterate until a condition is met.
int a = 0;while (a < 10) { a++;}
do-while Loops
do-while
loops are while
loops that initially execute the body once before checking the condition.
do { printf("not true!");} (while 2 == 3);
for Loops
for
loops complete a set number of iterations before meeting a condition.
for (int i = 0; i <= 10; i++) { printf("Hello!");}
Loop Keywords
All loops can utilize keywords like continue
and break
. continue
restarts the loop and break
breaks out of (or ends) the loop.
Rewriting Loops
A for
loop can always be re-written as a while
loop; most while
loops can be re-written as a for
loop.
Original Link: https://dev.to/ilosrim/lasson-04-loops-and-errors-4f5p
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To