Break keyword are used to stop loop permanently.
💻Example:
//Break Keyword
#include <stdio.h>
int main() {
for(int i=1;i<=10;i++)
{
if(i==5)
{
break;
}
printf("\n%d",i);
}
return 0;
}
⚙️ Output :
1
2
3
4
continue keyword are used to stop current loop.
💻Example:
//continue Keyword
#include <stdio.h>
int main() {
for(int i=1;i<=10;i++)
{
if(i==5)
{
continue;
}
printf("\n%d",i);
}
return 0;
}
⚙️ Output :
1
2
3
4
6
7
8
9
10
- Entry Controlled
- Pre-Tested Loop
- if condition will false it will run zero times
Syntax:
while(condion)
{
}
💻Example :
while(condition)
{
#include <stdio.h>
int main() {
int i=0;
while(i<5)
{
printf("\n%d",i);
i++;
}
return 0;
}
⚙️ Output :
0
1
2
3
4
- Exit Controlled
- Post-Tested Loop
- if condition will false it will run ones
Syntax:
do
{
}
while(condition);
💻Example:
#include <stdio.h>
int main() {
int i=0;
do
{
printf("\n%d",i);
i++;
}
while(i<5);
return 0;
}
⚙️ Output :
0
1
2
3
4