0
I have a program where there are three parameters. So:
These three parameters are positions within the m_aluno[w_i][w_j][w_k]);
, where w_i
can receive a position informed by the user or not and this serves to w_j
and w_k
also; My problem lies where, if a value for w_i
and soon w_j
and w_k
are empty, only the w_j
and the w_k
that will begin in 0
soon the w_i
shall be in an informed position!
My case is, "I want to add one loop only when necessary. How to do?"
I played Jsfiddle with all as condições
for better visualization (it was supposed to work, but I don’t know how to edit to run the function first).
Thus, there are três for's
:
for (w_i=0; w_i<w_ii; w_i++) //primeiro
{
for (w_j=0; w_j<w_jj; w_j++) //segundo
{
for (w_k=0; w_k<w_kk; w_k++) //terceiro
{
- If the
w_i
not start in0
the firstfor
has to go away. - If the
w_j
not start in0
the according tofor
has to go away. - If the
w_k
not start in0
the thirdfor
has to go away.
The w_i, w_j e w_k
just won’t start in 0 if the user gives some value to them.
Which language is using?
– Skywalker
I’m doing in
JavaScript
! It actually needs to be inJS
:x– Alexandre
I don’t quite understand what you’re trying to do. What does "add no to the value" mean? Perhaps it would be clearer if you gave a simplified example including your input and desired output
– hugomg
@hugomg I will edit for better understanding!
– Alexandre
@Alexandre
JS
=JavaScript
– Thomas
Yes I know @Thomas! In the above comment I am stating that it should be on
JS
^^– Alexandre
From what I understand, the noose will be done when
w_i
is informed, iteratingw_k
andw_j
. But until what value do you want to iterate the variables? The problem is not very clear and the nomenclature of the variables makes it even more confusing.– Thomas
@Thomas put in Jsfiddle to show how I had done before, it’s not running because I guess I’m not getting the function! (I don’t know how to edit there)
– Alexandre
I was doubtful about that part: if a value for w_i is given and then w_j and w_k are empty, only w_j should be iterated and w_k should start at 0 so w_i should be in the informed position!. Basically, if the College is informed, only the Room and Matter should be iterated in the
for
?– Eduardo Silva
Yes, and it would be the same if it were: It was informed only the room, then only the college and the matter should iterate in
for
. In the Jsfiddle example there are cases that may occur!– Alexandre
Those three loops, then, won’t cuddle as the code comes up, right? They will iterate independently as those NOT informed... that’s it?
– Thomas
Yes that’s right @Thomas
– Alexandre
@Alexandre I realize you need help, this code is not possible to keep this way... Can you also explain what you want to do? What functionality you need, so we can help you remake that code that’s too complex.
– Sergio
Sure @Sergio, my purpose is: I’m inserting inside the
m_aluno[w_i][w_j][w_k]
values in certain positions ( 0 , 0 , 0 ). And after inserting I would like to search what is contained in these certain positions! So it is my case to play the informed value (that would be the position) within thew_i
orw_j
orw_k
or even three or two values!– Alexandre
@Alexandre Mas a
Sala
, to exist, must be connected to aColégio
, right? For example, to list theSalas
available, it would not be easier to force the user to choose aColégio
rather than listing all theSalas
of all theColégios
?– Thomas
In that case, to choose one
w_j
, need to choose aw_i
. In fact, why not call itindice_colegio
? The purpose of the variable would be clearer in the code.– Thomas
Yes it is correct what you said, but if case is informed
2 colégios
2 salas
and2 matérias
. Do you agree that incolégio 1
would have2 salas
and2 matérias
and in thecolégio 2
the same right thing?– Alexandre
So if he wants to list the values that are only in
sala 2
, he will show ofcolégio 1
and ofcolégio 2
!– Alexandre