Loops
Entry Condition Loop:
Loops that are controlled by an entry condition execute the code block long as the condition remains true.
#include <iostream>
int main() {
int i = 0;
while (i < 5) {
std::cout << i << " ";
i++;
}
return 0;
}
#include<stdio.h>
int main() {
int i = 0;
while (i < 5) {
printf("%d", i);
i++;
}
return 0;
}
public class EntryConditionLoop {
public static void main(String[] args) {
int i = 0;
while (i < 5) {
System.out.print(i + " ");
i++;
}
}
}
i = 0
while i < 5:
print i,
i += 1
/ Initialize a variable i with the value 0.
let i = 0;
// Use a while loop to iterate while i is less than 5.
while (i < 5) {
// Print the current value of i to the console.
console.log(i + " ");
// Increment the value of i by 1.
i++;
}
Output
0 1 2 3 4
Exit Condition Loop:
Loops that are controlled by an exit condition execute the code block until the condition becomes false.
#include <iostream>
int main() {
int i = 0;
do {
std::cout << i << " ";
i++;
} while (i < 5);
return 0;
}
#include <stdio.h>
int main() {
int i = 0;
do {
printf("%d ", i);
i++;
} while (i < 5);
return 0;
}
public class ExitConditionLoop {
public static void main(String[] args) {
int i = 0;
do {
System.out.print(i + " ");
i++;
} while (i < 5);
}
}
i = 0
while i < 5:
print i,
i += 1
// Initialize a variable i with the value 0.
let i = 0;
// Use a do-while loop to ensure that the code inside
// the loop block is executed at least once.
do {
// Print the current value of i to the console.
console.log(i + " ");
// Increment the value of i by 1.
i++;
} while (i < 5);
Output
0 1 2 3 4
How to Start Coding
In this ever-evolving digital landscape, the ability to code is not just a valuable asset but a gateway to creative expression and innovation. This brief guide will outline practical steps and essential principles to guide aspiring learners on their path to mastering the art of coding.
Table of Content
- Introduction, to Basic Syntax. Hello World
- Understanding Data Types
- Variables and Constants
- Keywords
- Operators
- Decision Making statements
- Loops
- Numbers
- Characters
- Arrays
- Strings- Basic String Concepts
- Functions
Contact Us