+ 1
static int Pow(int x, int y = 2) { int result = 1; for (int i = 0; i < y; i++) /* this is the for loop that I don't understand.
4 Réponses
+ 2
woooo, I'll try to help. so int is the type of course, and in the parameter of int Pow, we have two options. int x, int y. the y is given a value in advance - so y by default will always be two. so if we do x - y, its saying x - 2. unless we change the parameter later which it does on the bottom half of the code in this section. so x is not defined, but y is defined as 2. the for (int I = 0 // this is a different call. they are not related to the original parameters and are a class being brought in to determine what happens to x. so if I is less than two, which it is cause its default is 0, then add one to I. so I is now 1.
+ 2
so essentially this is just determining if a l
oop goes. in this case it goes once. once it goes it will go again because I is still less than y. so twice it should output the next set of code which changes the pow class at the top. pow(6) is just pow int x = 6. while pow(6, 8) would change the default y to eight. so then this tells
+ 2
did that kinda answer your question? if not, let me know!
+ 1
oh gosh is can't type in this thing