Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-Exam-Practise/Loops/while.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
21 lines (17 sloc)
607 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
/* | |
While loops. Can also be known as a forever loop. | |
Breaks only when a condition is met; usually a boolean. | |
*/ | |
void while_loop(int max) { | |
int y = 0; // define variable to increment and match condition | |
while (y < max) { // condition when to stop:: when y is less than max, be false - stop | |
cout << y << " "; // iterate over it and print with a space after the number | |
y++; // increment by + 1 | |
} | |
} | |
int main() { | |
while_loop(10); // calling function, param -> max which will be in the condition of the while loop | |
return 0; | |
} |