forked from inspirezonetech/TeachMeCLikeIm5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
do-while-loops.c
37 lines (36 loc) · 1.29 KB
/
do-while-loops.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
------------------------------------------------------------------------------------
Tutorial: Do while loop
Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop in C programming checks its condition at the bottom of the loop.
A do...while loop is similar to a while loop, except the fact that it is guaranteed to execute at least one time.
------------------------------------------------------------------------------------
The general syntax for do-while-loops in C is:
do {
statement(s);
} while( condition );
------------------------------------------------------------------------------------
*/
// Example
#include <stdio.h>
int main()
{ // this is where the program start execution
// local variable declaration
int number = 2;
// do loop execution
do
{
printf("The number is: %d\n", number);
// increment in every step
number = number + 1;
// while loop execution
} while (number < 5);
return 0;
}
/*
------------------------------------------------------------------------------------
Challenges:
Using a do while loop:
1. Print all the numbers from 1 to 10.
2. Print all even numbers up to 5.
------------------------------------------------------------------------------------
*/