How to work this code ???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to work this code ????

/*C ++ Programming language */ #include <iostream> using namespace std; int main() { int x[10]={1,2,3,4,5,6,7,8,9,10}; /*how to work \/ this for loop I'm not understood this technic...*/ for (int y: x){ switch (y){ case 1:cout <<"S"; case 2:cout <<"A"; case 3:cout <<"T"; case 4:cout <<"Y"; case 5:cout <<"E"; case 6:cout <<"N"; case 7:cout <<"D"; case 8:cout <<"R"; case 9:cout <<"A"; case 10:cout <<" !"; cout<<endl; } } int y[10]={10,9,8,7,6,5,4,3,2,1}; for (int x: y){ switch (x){ case 1:cout <<"S"; case 2:cout <<"A"; case 3:cout <<"T"; case 4:cout <<"Y"; case 5:cout <<"E"; case 6:cout <<"N"; case 7:cout <<"D"; case 8:cout <<"R"; case 9:cout <<"A"; case 10:cout <<" !"; cout<<endl; } } return 0; }

30th Sep 2018, 2:57 PM
Satyendra Patel
Satyendra Patel - avatar
4 Answers
+ 8
It's a C++ code Loop in this code used is called Range-Based For Loop x is an integer array loop will iterate itself and the value of the current index in the array will be assigned to variable y on each iteration. Loop will terminate itself when it counters a null value in the array For more information visit these links: ¹https://www.geeksforgeeks.org/range-based-loop-c/amp/ ²https://en.cppreference.com/w/cpp/language/range-for
30th Sep 2018, 3:59 PM
blACk sh4d0w
blACk sh4d0w - avatar
0
Well what language is it first
30th Sep 2018, 3:07 PM
callum willcocks
callum willcocks - avatar
0
i dont understand the question, but maybe change the buffer to a container(like a vector)
30th Sep 2018, 3:38 PM
Bebida Roja
Bebida Roja - avatar
0
No I can't test the code without knowing which language it is
30th Sep 2018, 3:49 PM
callum willcocks
callum willcocks - avatar