Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 29, 2022 03:40 pm GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To