C++ for loops explained 🔂

preview_player
Показать описание
C++ for loops tutorial example explained

#for #loop #C++
Рекомендации по теме
Комментарии
Автор

#include <iostream>

int main()
{
for(int i = 10; i > 0; i--){
//count down to 10
std::cout << i << '\n';
}

std::cout << "HAPPY NEW YEAR!\n";

return 0;
}

BroCodez
Автор

#include <iostream>

int main(){

int count = 0;
char yorn;
std::string name[50];

do{
std::cout << "What do you want to put in your shopping bag? ";
std::cin >> name[count];
std::cout << count+1 << ". " << name[count];

std::cout << '\n' << "would you like to continue Y or N? ";
std::cin >> yorn;

count++;

}while (yorn == 'Y' || yorn == 'y');


std::cout << '\n' << "Here is your shoppinglist : " << '\n';

for ( int counter = 1; counter <= count; counter++ ){

std::cout << counter << ". " << name[counter-1] << '\n';

}

return 0;

}

colad
Автор

#include <iostream>

int main(){

for(int i=10; i >= 1; i--){
std::cout << "GAME ENDING IN: " << i << "\n";
}


return 0;
}

Nati-uuph
Автор

Quite don't understand the initialization statement can you help me whats the counter means

insnutty
Автор

Think he wanted to while 10 is greater than or equal to =0. 10 was I in the code but yeah.

Chemhandle
Автор

#include <iostream>
#include <string>


int main()
{
for (int i = 1; i <= 10; i++) {
std::cout << i << "\n";

}

std::cout << "Countdown worked!";
return 0;
}

Gavin_NA
Автор

int main(){

std::string weekDays[7] = {"Monday\n", "Tuesday\n", "Wednesday\n", "Thursday\n", "Friday\n", "Saturday\n", "Sunday\n"};
int input;


for (int i = 0; i < 7; i++){
std::cout << weekDays[i];

}




return 0;

}

sohungry
Автор

#include <iostream>

int main () {

for (int i=10; i>=1; i-- ) {

std::cout << i << "\n";
}

return 0;
}

Yousif_Maksabo
Автор

How come the stopping condition has to be less than and equal? I used just equal and it infinitely looped it. Why is this?

lastwaveundergroundsaviour
Автор

#include <iostream>

int main(){
For(int i =0;i>= 0;i-=2)
std::cout>>”this doesn’t even display something”\’n’;
//this literally doesn’t do anything I wrote this as an assignment

return 0;}

parpaperchimp
Автор

int main(){
for(int i = 3; i > 0; i--){
std::cout << i << '\n';
}

std::cout << "BOOM";

JayChit
Автор

You're such a huge help


my try:



#include <iostream>
#include <unistd.h>


int main() {
for (int i = 1; i <= 10; i++) {
std::cout << i << std::endl;
sleep(1);
}
std::cout << "I finished my counting" << std::endl;
std::cout << "aren't I'm the coolest, lol. I will keep counting now though" << std::endl;
for (int i = 10; i <= 20; i++) {
std::cout << i << std::endl;

}
std::cout << "OMG I AM THE COUNT << std::endl;
}

Lokvie